discord_read_messages
Retrieve messages from Discord text channels to monitor conversations, analyze discussions, or gather information with configurable limits.
Instructions
Retrieves messages from a Discord text channel with a configurable limit
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| channelId | Yes | ||
| limit | No |
Implementation Reference
- src/index.ts:862-928 (handler)Handler function that fetches messages from a specified Discord channel using the discord.js client, validates input with ReadMessagesSchema, formats message details including author, timestamp, attachments, embeds, and replies, sorts them chronologically, and returns formatted JSON response.case "discord_read_messages": { const { channelId, limit } = ReadMessagesSchema.parse(args); try { if (!client.isReady()) { return { content: [{ type: "text", text: "Discord client not logged in. Please use discord_login tool first." }], isError: true }; } const channel = await 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 { content: [{ type: "text", text: `Failed to read messages: ${error}` }], isError: true }; } }
- src/index.ts:179-182 (schema)Zod schema used for input validation in the discord_read_messages handler, defining channelId as required string and limit as optional number between 1-100 defaulting to 50.const ReadMessagesSchema = z.object({ channelId: z.string(), limit: z.number().min(1).max(100).optional().default(50) });
- src/index.ts:306-318 (schema)JSON schema for input validation exposed via the MCP ListTools endpoint for the discord_read_messages tool.inputSchema: { type: "object", properties: { channelId: { type: "string" }, limit: { type: "number", minimum: 1, maximum: 100, default: 50 } }, required: ["channelId"] }
- src/index.ts:303-319 (registration)Tool registration in the ListTools response array, defining name, description, and input schema for discord_read_messages.{ 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"] } },