get_pinned_messages
Retrieve all pinned messages from a Discord channel by providing server and channel IDs. This tool helps users access important announcements and saved content in Discord servers.
Instructions
Get all pinned messages in a channel
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| guildId | Yes | The ID of the server (guild) | |
| channelId | Yes | The ID of the channel |
Implementation Reference
- src/tools/message-tools.ts:292-316 (handler)The main handler function for the 'get_pinned_messages' tool. It fetches the Discord guild and channel, validates the channel type, retrieves pinned messages using Discord.js fetchPinned(), maps them to a simplified object, wraps in error handling, and returns JSON-formatted response.const result = await withErrorHandling(async () => { const client = await getDiscordClient(); const guild = await client.guilds.fetch(guildId); const channel = await guild.channels.fetch(channelId); if (!isMessageableChannel(channel)) { throw new Error('Channel does not support messages'); } const pinned = await channel.messages.fetchPinned(); return pinned.map((msg) => ({ id: msg.id, content: msg.content, authorId: msg.author.id, authorUsername: msg.author.username, createdAt: msg.createdAt.toISOString(), })); }); if (!result.success) { return { content: [{ type: 'text', text: result.error }], isError: true }; } return { content: [{ type: 'text', text: JSON.stringify(result.data, null, 2) }] }; }
- src/tools/message-tools.ts:288-291 (schema)Zod input schema defining required parameters: guildId (string) and channelId (string).guildId: z.string().describe('The ID of the server (guild)'), channelId: z.string().describe('The ID of the channel'), }, async ({ guildId, channelId }) => {
- src/tools/message-tools.ts:285-317 (registration)Direct registration of the 'get_pinned_messages' tool on the McpServer using server.tool(), specifying name, description, input schema, and inline handler function.'get_pinned_messages', 'Get all pinned messages in a channel', { guildId: z.string().describe('The ID of the server (guild)'), channelId: z.string().describe('The ID of the channel'), }, async ({ guildId, channelId }) => { const result = await withErrorHandling(async () => { const client = await getDiscordClient(); const guild = await client.guilds.fetch(guildId); const channel = await guild.channels.fetch(channelId); if (!isMessageableChannel(channel)) { throw new Error('Channel does not support messages'); } const pinned = await channel.messages.fetchPinned(); return pinned.map((msg) => ({ id: msg.id, content: msg.content, authorId: msg.author.id, authorUsername: msg.author.username, createdAt: msg.createdAt.toISOString(), })); }); if (!result.success) { return { content: [{ type: 'text', text: result.error }], isError: true }; } return { content: [{ type: 'text', text: JSON.stringify(result.data, null, 2) }] }; } );
- src/index.ts:59-59 (registration)Top-level call to registerMessageTools(server) within createMcpServer(), which triggers the registration of get_pinned_messages and other message tools.registerMessageTools(server);