Skip to main content
Glama

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

Implementation Reference

  • 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) }] }; }
  • 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'), },
  • 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';

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