get_channel_info
Retrieve detailed information about a specific Discord channel using server and channel IDs to manage and maintain Discord servers.
Instructions
Get detailed information about a specific 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/channel-tools.ts:56-118 (handler)The core handler function that fetches the Discord guild and channel, extracts base and type-specific information (text/voice), handles permissions and errors, and returns JSON-formatted data.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 (!channel) throw new Error('Channel not found'); // Cast to GuildChannel for common properties const guildChannel = channel as GuildChannel; const baseInfo: Record<string, unknown> = { id: channel.id, name: channel.name, type: channel.type, typeName: ChannelType[channel.type], parentId: guildChannel.parentId, createdAt: channel.createdAt?.toISOString(), }; // Add position and permission overwrites for non-thread channels if ('position' in guildChannel) { baseInfo.position = guildChannel.position; } if ('permissionOverwrites' in guildChannel && guildChannel.permissionOverwrites) { baseInfo.permissionOverwrites = guildChannel.permissionOverwrites.cache.map((po) => ({ id: po.id, type: po.type, allow: po.allow.toArray(), deny: po.deny.toArray(), })); } // Add text channel specific info if (channel.type === ChannelType.GuildText || channel.type === ChannelType.GuildAnnouncement) { const textChannel = channel as TextChannel; return { ...baseInfo, topic: textChannel.topic, nsfw: textChannel.nsfw, rateLimitPerUser: textChannel.rateLimitPerUser, }; } // Add voice channel specific info if (channel.type === ChannelType.GuildVoice || channel.type === ChannelType.GuildStageVoice) { const voiceChannel = channel as VoiceChannel; return { ...baseInfo, bitrate: voiceChannel.bitrate, userLimit: voiceChannel.userLimit, rtcRegion: voiceChannel.rtcRegion, }; } return baseInfo; }); 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/channel-tools.ts:52-55 (schema)Zod input schema defining required guildId and channelId parameters.{ guildId: z.string().describe('The ID of the server (guild)'), channelId: z.string().describe('The ID of the channel'), },
- src/tools/channel-tools.ts:49-119 (registration)Registration of the 'get_channel_info' tool on the MCP server within registerChannelTools function.server.tool( 'get_channel_info', 'Get detailed information about a specific 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 (!channel) throw new Error('Channel not found'); // Cast to GuildChannel for common properties const guildChannel = channel as GuildChannel; const baseInfo: Record<string, unknown> = { id: channel.id, name: channel.name, type: channel.type, typeName: ChannelType[channel.type], parentId: guildChannel.parentId, createdAt: channel.createdAt?.toISOString(), }; // Add position and permission overwrites for non-thread channels if ('position' in guildChannel) { baseInfo.position = guildChannel.position; } if ('permissionOverwrites' in guildChannel && guildChannel.permissionOverwrites) { baseInfo.permissionOverwrites = guildChannel.permissionOverwrites.cache.map((po) => ({ id: po.id, type: po.type, allow: po.allow.toArray(), deny: po.deny.toArray(), })); } // Add text channel specific info if (channel.type === ChannelType.GuildText || channel.type === ChannelType.GuildAnnouncement) { const textChannel = channel as TextChannel; return { ...baseInfo, topic: textChannel.topic, nsfw: textChannel.nsfw, rateLimitPerUser: textChannel.rateLimitPerUser, }; } // Add voice channel specific info if (channel.type === ChannelType.GuildVoice || channel.type === ChannelType.GuildStageVoice) { const voiceChannel = channel as VoiceChannel; return { ...baseInfo, bitrate: voiceChannel.bitrate, userLimit: voiceChannel.userLimit, rtcRegion: voiceChannel.rtcRegion, }; } return baseInfo; }); 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)Invocation of registerChannelTools in the main MCP server setup.registerChannelTools(server);
- src/index.ts:12-12 (registration)Import of the registerChannelTools function.import { registerChannelTools } from './tools/channel-tools.js';