pin_message
Pin important messages in Discord channels to keep them visible and accessible for server members.
Instructions
Pin a message 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 | |
| messageId | Yes | The ID of the message to pin | |
| reason | No | Reason for pinning |
Implementation Reference
- src/tools/message-tools.ts:227-247 (handler)Handler function that fetches the Discord guild, channel, and message, validates the channel type, pins the message using the Discord.js message.pin() method with optional reason, handles errors via withErrorHandling, and returns formatted success or error response.async ({ guildId, channelId, messageId, reason }) => { 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 message = await channel.messages.fetch(messageId); await message.pin(reason); return { messageId, message: 'Message pinned successfully' }; }); 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:221-226 (schema)Zod schema for input parameters of the pin_message tool: required guildId, channelId, messageId; optional reason.{ guildId: z.string().describe('The ID of the server (guild)'), channelId: z.string().describe('The ID of the channel'), messageId: z.string().describe('The ID of the message to pin'), reason: z.string().optional().describe('Reason for pinning'), },
- src/tools/message-tools.ts:218-248 (registration)Registration of the pin_message tool via server.tool() call inside registerMessageTools function, specifying name, description, input schema, and handler.server.tool( 'pin_message', 'Pin a message in a channel', { guildId: z.string().describe('The ID of the server (guild)'), channelId: z.string().describe('The ID of the channel'), messageId: z.string().describe('The ID of the message to pin'), reason: z.string().optional().describe('Reason for pinning'), }, async ({ guildId, channelId, messageId, reason }) => { 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 message = await channel.messages.fetch(messageId); await message.pin(reason); return { messageId, message: 'Message pinned successfully' }; }); 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:58-58 (registration)Invocation of registerMessageTools(server) in createMcpServer(), which registers the pin_message tool as part of message tools.registerMessageTools(server);
- src/tools/message-tools.ts:9-17 (helper)Helper type guard function used in pin_message handler to validate if the fetched channel supports sending messages (TextChannel, NewsChannel, ThreadChannel).function isMessageableChannel(channel: unknown): channel is MessageableChannel { if (!channel || typeof channel !== 'object') return false; const ch = channel as { type?: number }; return ch.type === ChannelType.GuildText || ch.type === ChannelType.GuildAnnouncement || ch.type === ChannelType.PublicThread || ch.type === ChannelType.PrivateThread || ch.type === ChannelType.AnnouncementThread; }