Skip to main content
Glama

list_channels

Retrieve all channels in a Discord server by providing the server ID. Use this tool to view channel names, types, and permissions for server management.

Instructions

List all channels in a Discord server

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
guildIdYesThe ID of the server (guild)

Implementation Reference

  • Handler function for the 'list_channels' tool. Fetches all channels from the specified Discord guild, maps them to an object with id, name, type, typeName, parentId, and position, filters out invalid channels, handles errors using withErrorHandling, and returns the JSON-formatted list or an error message.
    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) }] }; }
  • Input schema for 'list_channels' tool using Zod validation. Requires a single parameter: guildId (string, ID of the Discord server/guild).
    { guildId: z.string().describe('The ID of the server (guild)'), },
  • MCP server.tool registration for 'list_channels', including name, description, input schema, and inline handler function.
    server.tool( '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:54-54 (registration)
    Invocation of registerChannelTools(server) which registers the list_channels tool (among others) to 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