# Search Server Messages

> Search a server's messages and iterate over the matched messages.

- ID: `search_discord_guild_messages`
- Type: Loop
- Category: [Messages](https://inventor.bot/docs/reference/blocks/messages.md)

- Loop block: write `for item := range search_discord_guild_messages(Args{...}) { ... }` and read the current item's outputs from `item`. See loops.

**Inputs**

| Name | Required | Description | Value |
| --- | --- | --- | --- |
| `server_id` | yes | ID of the server to search in. |  |
| `search_content` | yes | Text to search for in message content. | e.g. `"hello world"` |
| `channel_ids` |  | Optional comma-separated channel IDs to restrict the search to. |  |
| `author_ids` |  | Optional comma-separated author user IDs to restrict the search to. |  |
| `mention_ids` |  | Optional comma-separated user IDs that must be mentioned. |  |
| `has_filters` |  | Optional comma-separated has filters, such as attachment, sound, or poll. |  |
| `min_message_id` |  | Only include messages newer than this message ID. |  |
| `max_message_id` |  | Only include messages older than this message ID. |  |
| `mention_everyone` |  | Filter by whether matched messages mention @everyone or @here. | `"Any"`, `"true"`, `"false"` |
| `sort_by` |  | How the search results should be sorted. | `"relevance"`, `"timestamp"` |
| `sort_order` |  | Whether results should be sorted ascending or descending. | `"desc"`, `"asc"` |
| `offset` |  | Pagination offset to start from (0-5000). | e.g. `"0"` |
| `limit` |  | Maximum matched messages to return (1-25, default 25). | e.g. `"25"` |
| `body` |  | Blocks to run for each matched message. | blocks: `func() { ... }` |

**Outputs**

| Name | Description | Value |
| --- | --- | --- |
| `iteration_number` | Current iteration (1-based). | e.g. `"1"` |
| `total_iterations` | Total matched messages returned in this page. | e.g. `"25"` |
| `total_results` | Total number of matched messages reported by Discord. | e.g. `"240"` |
| `analytics_id` | Opaque analytics identifier returned by Discord for this search. |  |
| `message_id` | ID of the message. | e.g. `"123456789012345678"` |
| `channel_id` | ID of the channel containing the message. | e.g. `"123456789012345678"` |
| `server_id` | ID of the server containing the message. | e.g. `"123456789012345678"` |
| `content` | Text content of the message. |  |
| `author_id` | ID of the message author. | e.g. `"123456789012345678"` |
| `author_username` | Username of the message author. |  |
| `author_global_name` | Display name of the message author. |  |
| `author_avatar_url` | Avatar URL of the message author. |  |
| `author_mention` | Mention string for the message author. | e.g. `"<@123456789012345678>"` |
| `author_is_bot` | Whether the message author is a bot. | e.g. `"false"` |
| `message_sent_at` | Unix timestamp when the message was sent. | e.g. `"1640995200"` |
| `message_edited_at` | Unix timestamp when the message was last edited. Empty if never edited. |  |
| `is_pinned` | Whether the message is pinned. | e.g. `"false"` |
| `is_tts` | Whether the message is text-to-speech. | e.g. `"false"` |
| `mention_everyone` | Whether the message mentions everyone. | e.g. `"false"` |
| `user_mentions` | Comma-separated IDs of mentioned users. | e.g. `"123456789012345678,987654321098765432"` |
| `role_mentions` | Comma-separated IDs of mentioned roles. | e.g. `"123456789012345678,987654321098765432"` |
| `attachment_count` | Number of attachments on the message. | e.g. `"0"` |
| `attachment_urls` | Comma-separated URLs of message attachments. |  |
| `embed_count` | Number of embeds on the message. | e.g. `"0"` |
| `reply_to_message_id` | ID of the message this is replying to. Empty if not a reply. |  |
| `webhook_id` | Webhook ID if the message was sent by a webhook. |  |
| `message_link` | Direct link to the message. | e.g. `"https://discord.com/channels/123/456/789"` |
| `thread_id` | ID of the thread started from this message. Empty if none. |  |
| `sticker_ids` | Comma-separated IDs of stickers on the message. |  |
| `embed_title` | Title of the first embed. For Components v2 messages, the leading "## " heading in the first container. |  |
| `embed_description` | Description of the first embed. For Components v2 messages, the first plain text in the first container. |  |
| `embed_url` | URL of the first embed. |  |
| `embed_color` | Color of the first embed as a decimal integer. For Components v2 messages, the first container's accent color. | e.g. `"3447003"` |
| `embed_image_url` | Image URL of the first embed. For Components v2 messages, the first gallery image in the first container. |  |
| `embed_thumbnail_url` | Thumbnail URL of the first embed. For Components v2 messages, the first section thumbnail in the first container. |  |
| `embed_footer_text` | Footer text of the first embed. For Components v2 messages, the "-# " subtext in the first container. |  |
| `embed_footer_icon_url` | Footer icon URL of the first embed. |  |
| `embed_author_name` | Author name of the first embed. |  |
| `embed_author_url` | Author URL of the first embed. |  |
| `embed_author_icon_url` | Author icon URL of the first embed. |  |
| `embed_timestamp` | Timestamp of the first embed. |  |
| `embed_timestamp_unix` | Unix timestamp of the first embed. |  |
| `is_components_v2` | Whether the message uses Components v2 (sent by Send Advanced Message or Send Embed Message blocks). | e.g. `"false"` |
| `text_content` | All Components v2 text in the message, including text inside containers and sections, joined by newlines. |  |
| `container_accent_color` | Accent color of the first Components v2 container as a decimal integer. | e.g. `"3447003"` |
| `media_urls` | Comma-separated URLs of Components v2 gallery images and thumbnails. |  |

**Example**

```go
for searchGuildMessage := range search_discord_guild_messages(Args{server_id: trigger.server_id, search_content: "hello world"}) {
	send_text_message(Args{
		channel_id:      trigger.channel_id,
		message_content: "Total Results: " + searchGuildMessage.total_results,
	})
}
```