Skip to main content
Glama

discord_read_messages

Retrieve messages from Discord text channels to monitor conversations, analyze discussions, or gather information with configurable limits for efficient data collection.

Instructions

Retrieves messages from a Discord text channel with a configurable limit

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
channelIdYes
limitNo

Implementation Reference

  • Main handler function that parses arguments, fetches the Discord channel, retrieves the specified number of recent messages, formats them with details like author, timestamp, attachments, and returns structured JSON response.
    export async function readMessagesHandler( args: unknown, context: ToolContext ): Promise<ToolResponse> { const { channelId, limit } = ReadMessagesSchema.parse(args); try { if (!context.client.isReady()) { return { content: [{ type: 'text', text: 'Discord client not logged in.' }], isError: true, }; } const channel = await context.client.channels.fetch(channelId); if (!channel) { return { content: [ { type: 'text', text: `Cannot find channel with ID: ${channelId}` }, ], isError: true, }; } // Check if channel has messages (text channel, thread, etc.) if (!(channel.isTextBased() && 'messages' in channel)) { return { content: [ { type: 'text', text: 'Channel type does not support reading messages', }, ], isError: true, }; } // Fetch messages const messages = await channel.messages.fetch({ limit }); if (messages.size === 0) { return { content: [{ type: 'text', text: 'No messages found in channel' }], }; } // Format messages const formattedMessages = messages .map((msg) => ({ id: msg.id, content: msg.content, author: { id: msg.author.id, username: msg.author.username, bot: msg.author.bot, }, timestamp: msg.createdAt, attachments: msg.attachments.size, embeds: msg.embeds.length, replyTo: msg.reference ? msg.reference.messageId : null, })) .sort((a, b) => a.timestamp.getTime() - b.timestamp.getTime()); return { content: [ { type: 'text', text: JSON.stringify( { channelId, messageCount: formattedMessages.length, messages: formattedMessages, }, null, 2 ), }, ], }; } catch (error) { return handleDiscordError(error); } }
  • MCP tool schema defining the name, description, input parameters (channelId required, limit optional 1-100 default 50), and validation.
    { name: 'discord_read_messages', description: 'Retrieves messages from a Discord text channel with a configurable limit', inputSchema: { type: 'object', properties: { channelId: { type: 'string' }, limit: { type: 'number', minimum: 1, maximum: 100, default: 50, }, }, required: ['channelId'], }, },
  • src/server.ts:151-154 (registration)
    Registers and dispatches the discord_read_messages tool call to the readMessagesHandler function within the MCP server's CallToolRequestSchema handler.
    case 'discord_read_messages': this.logClientState('before discord_read_messages handler'); toolResponse = await readMessagesHandler(args, this.toolContext); return toolResponse;
  • Re-exports the readMessagesHandler from channel.ts for convenient import in server.ts and transport.ts.
    export { createCategoryHandler, createTextChannelHandler, deleteCategoryHandler, deleteChannelHandler, editCategoryHandler, getServerInfoHandler, readMessagesHandler,

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/IQAIcom/mcp-discord'

If you have feedback or need assistance with the MCP directory API, please join our Discord server