Skip to main content
Glama
scarecr0w12

discord-mcp

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
NameRequiredDescriptionDefault
guildIdYesThe ID of the server (guild)
channelIdYesThe ID of the channel

Implementation Reference

  • 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) }] };
    }
  • 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 }) => {
  • 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);

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/scarecr0w12/discord-mcp'

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