Skip to main content

Get Channel Messages

Retrieves messages from a Discord channel with pagination support.

Common Properties

  • Name - The custom name of the node.
  • Color - The custom color of the node.
  • Delay Before (sec) - Waits in seconds before executing the node.
  • Delay After (sec) - Waits in seconds after executing node.
  • Continue On Error - Automation will continue regardless of any error. The default value is false.
info

If the ContinueOnError property is true, no error is caught when the project is executed, even if a Catch node is used.

Inputs

  • Client Id - The Discord bot client identifier from the Connect node (optional if Bot Token provided).
  • Channel Id - The ID of the Discord channel to retrieve messages from.
  • Message Id - A reference message ID for pagination (retrieve messages before or after this message).

Options

  • Bot Token - Discord bot token credential (optional if using Client ID from Connect node).
  • Limit - Maximum number of messages to retrieve (default: 10, max: 100).
  • Direction - Direction to fetch messages relative to the reference message:
    • Before - Get messages older than the reference message
    • After - Get messages newer than the reference message

Output

  • Messages - An array of message objects retrieved from the channel.

How It Works

The Get Channel Messages node retrieves historical messages from a Discord channel. When executed, the node:

  1. Authenticates using either Client ID or direct bot token
  2. Validates the channel ID and message ID
  3. Determines the pagination direction
  4. Requests messages from Discord API
  5. Returns an array of message objects

Requirements

  • Active Discord bot session (Client ID) or bot token credentials
  • Valid channel ID and reference message ID
  • Read Message History permission in the channel
  • The bot must be a member of the server

Error Handling

The node will return specific errors in the following cases:

  • ErrInvalidArg - Client ID or bot token missing/invalid
  • ErrInvalidArg - Channel ID is empty
  • ErrInvalidArg - Message ID is empty
  • ErrInvalidArg - Direction is not selected
  • Discord API errors (missing permissions, channel not found, etc.)

Message Object Structure

Each message in the array contains:

{
"ID": "123456789012345678",
"ChannelID": "987654321098765432",
"GuildID": "111111111111111111",
"Content": "Hello, world!",
"Timestamp": "2024-01-15T10:30:00Z",
"Author": {
"ID": "222222222222222222",
"Username": "JohnDoe"
},
"Attachments": [],
"Embeds": [],
"Reactions": []
}

Pagination

Use pagination to retrieve large message histories:

Get first 10 messages:

1. Get the most recent message ID
2. Get Channel Messages
- Message Id: (most recent)
- Direction: Before
- Limit: 10

Get next 10 messages:

1. Use the ID of the oldest message from previous request
2. Get Channel Messages
- Message Id: (oldest from previous)
- Direction: Before
- Limit: 10

Example: Retrieve Recent Messages

Inputs:

  • Channel Id: "123456789012345678"
  • Message Id: "999999999999999999" (latest message)
  • Direction: "Before"
  • Limit: 50

Result: Returns up to 50 messages older than the reference message.

Example: Search Message History

Flow:

1. Get Channel Messages → messages
2. For each message in messages:
- Condition: message.Content contains "error"
- If True:
- Log: "Found error in message {{message.ID}}"

Result: Search through messages for specific content.

Example: Archive Channel

Flow:

1. Get latest message ID
2. Loop:
- Get Channel Messages
- Message Id: {{current_message_id}}
- Direction: Before
- Limit: 100
- Save messages to file
- Update current_message_id to oldest message
- Repeat until no more messages

Result: Archive entire channel history.

Example: Analyze Message Activity

Flow:

1. Get Channel Messages (last 100)
2. Count messages by author
3. Generate activity report

Use Cases

  • Message archival - Back up channel history
  • Content moderation - Review recent messages
  • Analytics - Analyze message patterns and activity
  • Search - Find specific messages or content
  • Migration - Export messages to another platform
  • Audit logging - Track conversation history
  • Data extraction - Extract information from past messages

Accessing Message Data

Loop through the messages array:

For each message in {{messages}}:
- Author: {{message.Author.Username}}
- Content: {{message.Content}}
- Time: {{message.Timestamp}}

Limitations

  • Maximum 100 messages per request
  • Cannot retrieve messages older than the channel's creation
  • Deleted messages are not included
  • System messages are included
  • Requires Read Message History permission

Bot Permissions Required

  • View Channel - See the channel
  • Read Message History - Read past messages

Rate Limits

Discord has rate limits for message retrieval:

  • Limit: 50 requests per second
  • Consider adding delays when retrieving large histories
  • Use the largest practical limit (up to 100) to minimize requests

Tips and Best Practices

  • Efficient pagination - Use limit=100 for fewer API calls
  • Reference point - Start from the most recent message
  • Error handling - Handle cases where channel is empty
  • Rate limiting - Add delays when processing many pages
  • Storage - Save retrieved messages to avoid re-fetching
  • Filtering - Filter messages in your flow rather than fetching repeatedly
  • Permissions - Verify Read Message History permission before fetching