# Search messages

> Find messages in the server with Discord's own search.

Source: https://docs.buildcord.dev/nodes/server/search-messages/

`server.search` searches the server's messages the way Discord's search bar does, and hands back what it finds as a list.

## Settings

| Setting | What it does |
| --- | --- |
| Words | What to search for, such as `{option.query}`. |
| In channels | Only these channels or threads: ids or mentions, separated by commas. Empty is every channel. |
| Never in | Channels to leave out, along with the threads in them. The channel the flow was used in is still searched. |
| From | Only messages by these members. |
| Mentioning, Mentioning roles | Only messages that mention these members, or roles. |
| Mentions @everyone | Only messages that do, or only those that don't. |
| Replying to members, Replying to messages | Only replies to these members, or to these messages by id. |
| Has | Any of image, sound, video, file, sticker, embed, link, poll and snapshot. Put `-` in front to leave those out, such as `-link`. |
| Written by | user, bot or webhook. Put `-` in front to leave those out, such as `-bot`. |
| Pinned | Only pinned messages, or only those that aren't. |
| After message, Before message | Only messages after, or before, this one. |
| Sorted by | Newest first, oldest first, or most relevant. |
| Direction | Ascending or descending, overriding the one the sort gives, such as most relevant last. |
| Bring back | How many, up to 25. |
| Skip the first | For the next page: skip as many as were brought back before. |
| Only channels they can read | On by default. Searches only where the member who set the flow off can read the history. |
| Include age-restricted channels | Off by default. |
| Links to, Files ending in, Files named | Only messages linking to these hostnames, or with these files. |
| Embeds of kind, Embeds from | Only messages with these kinds of embed, or embeds from these providers, such as YouTube. |
| Words between | How many words may come between the words searched for. |

## Ways out

| Way out | When |
| --- | --- |
| `found` | Something matched. |
| `none` | Nothing did. |

## Tokens

| Token | Value |
| --- | --- |
| `{search.results}` | The messages found, as a list. Each has `id`, `channel`, `channelMention`, `link`, `content`, `at`, `pinned`, `files`, `embeds`, `replyTo` and `author` (`id`, `name`, `mention`, `bot`, `avatar`). |
| `{search.count}` | How many came back |
| `{search.total}` | How many match in all |
| `{search.skipped}` | Channels named in **In channels** that **Never in** left out |

Go through the results with [For each item](https://docs.buildcord.dev/nodes/flow-control/for-each) and `{loop.item.content}`, or turn them into a message in [Run code](https://docs.buildcord.dev/nodes/integrations/run-code).

## Notes

- The bot needs Read Message History in the channels it searches.
- Discord takes a moment to index a server the first time it's searched. The step waits up to eight seconds, then fails.
