# Get Messages

> Fetch recent messages from a channel and iterate over them.

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

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

**Inputs**

| Name | Required | Description | Value |
| --- | --- | --- | --- |
| `channel_id` | yes | ID of the channel to fetch messages from. |  |
| `limit` | yes | Number of messages to fetch (max 100). | e.g. `"50"` |
| `before_id` |  | Fetch messages before this message ID. |  |
| `after_id` |  | Fetch messages after this message ID. |  |
| `around_id` |  | Fetch messages around this message ID. |  |
| `body` |  | Blocks to run for each message. | blocks: `func() { ... }` |

**Outputs**

| Name | Description | Value |
| --- | --- | --- |
| `iteration_number` | Current iteration (1-based). | e.g. `"1"` |
| `total_iterations` | Total number of messages returned. | e.g. `"50"` |
| `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 channelMessage := range get_discord_channel_messages(Args{channel_id: trigger.channel_id, limit: 50}) {
	send_text_message(Args{
		channel_id:      trigger.channel_id,
		message_content: "Message ID: " + channelMessage.message_id,
	})
}
```