get_channel_permissions
Retrieve permission overwrites for a Discord channel to manage role and member access controls within a server.
Instructions
Get all permission overwrites for 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 |
Implementation Reference
- src/tools/permission-tools.ts:16-61 (handler)The main handler function that fetches the Discord guild and channel, retrieves permission overwrites, resolves role/member names, and formats the response.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'); const overwrites = (channel as GuildChannel).permissionOverwrites.cache.map((overwrite) => ({ id: overwrite.id, type: overwrite.type === OverwriteType.Role ? 'role' : 'member', allow: overwrite.allow.toArray(), deny: overwrite.deny.toArray(), })); // Get role/member names for context const resolvedOverwrites = await Promise.all( overwrites.map(async (ow) => { let name = 'Unknown'; if (ow.type === 'role') { const role = await guild.roles.fetch(ow.id); name = role?.name ?? 'Unknown Role'; } else { try { const member = await guild.members.fetch(ow.id); name = member.displayName; } catch { name = 'Unknown Member'; } } return { ...ow, name }; }) ); return { channelId, channelName: channel.name, overwrites: resolvedOverwrites, }; }); 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/permission-tools.ts:12-15 (schema)Zod schema defining the input parameters: guildId and channelId.{ guildId: z.string().describe('The ID of the server (guild)'), channelId: z.string().describe('The ID of the channel'), },
- src/tools/permission-tools.ts:9-62 (registration)The server.tool() call that registers the get_channel_permissions tool with its schema and handler function.server.tool( 'get_channel_permissions', 'Get all permission overwrites for 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 (!channel) throw new Error('Channel not found'); const overwrites = (channel as GuildChannel).permissionOverwrites.cache.map((overwrite) => ({ id: overwrite.id, type: overwrite.type === OverwriteType.Role ? 'role' : 'member', allow: overwrite.allow.toArray(), deny: overwrite.deny.toArray(), })); // Get role/member names for context const resolvedOverwrites = await Promise.all( overwrites.map(async (ow) => { let name = 'Unknown'; if (ow.type === 'role') { const role = await guild.roles.fetch(ow.id); name = role?.name ?? 'Unknown Role'; } else { try { const member = await guild.members.fetch(ow.id); name = member.displayName; } catch { name = 'Unknown Member'; } } return { ...ow, name }; }) ); return { channelId, channelName: channel.name, overwrites: resolvedOverwrites, }; }); 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:57-57 (registration)Invocation of registerPermissionTools(server) which registers the permission tools including get_channel_permissions.registerPermissionTools(server);
- src/index.ts:15-15 (registration)Import of the registerPermissionTools function.import { registerPermissionTools } from './tools/permission-tools.js';