Skip to main content
Glama

list_channels

Retrieve all channels in a Discord server by providing the server ID to manage and organize your community spaces.

Instructions

List all channels in a Discord server

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
guildIdYesThe ID of the server (guild)

Implementation Reference

  • The handler function that executes the tool logic: fetches Discord client, retrieves guild by ID, fetches all channels, maps to structured data (id, name, type, parentId, position), filters valid channels, handles errors with withErrorHandling, and returns JSON-formatted response.
    async ({ guildId }) => { const result = await withErrorHandling(async () => { const client = await getDiscordClient(); const guild = await client.guilds.fetch(guildId); const channels = await guild.channels.fetch(); return channels.map((ch) => ({ id: ch?.id, name: ch?.name, type: ch?.type, typeName: ChannelType[ch?.type ?? 0], parentId: (ch as GuildChannel)?.parentId, position: (ch as GuildChannel)?.position, })).filter((ch) => ch.id); }); 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 the required 'guildId' parameter as a string.
    guildId: z.string().describe('The ID of the server (guild)'), },
  • Tool registration using McpServer.tool() method, specifying name 'list_channels', description, input schema, and inline handler function.
    'list_channels', 'List all channels in a Discord server', { guildId: z.string().describe('The ID of the server (guild)'), }, async ({ guildId }) => { const result = await withErrorHandling(async () => { const client = await getDiscordClient(); const guild = await client.guilds.fetch(guildId); const channels = await guild.channels.fetch(); return channels.map((ch) => ({ id: ch?.id, name: ch?.name, type: ch?.type, typeName: ChannelType[ch?.type ?? 0], parentId: (ch as GuildChannel)?.parentId, position: (ch as GuildChannel)?.position, })).filter((ch) => ch.id); }); 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:55-55 (registration)
    Call to registerChannelTools function which registers the list_channels tool (and other channel tools) on the MCP server instance.
    registerChannelTools(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