Skip to main content
Glama
scarecr0w12

discord-mcp

get_channel_permissions

Retrieve all permission overwrites for a Discord channel to manage access controls and role-based permissions 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 handler function that implements the core logic of fetching channel permission overwrites, resolving names for roles/members, and returning formatted JSON.
    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) }] };
    }
  • Input schema using Zod for validating guildId and channelId parameters.
    {
      guildId: z.string().describe('The ID of the server (guild)'),
      channelId: z.string().describe('The ID of the channel'),
    },
  • Registration of the 'get_channel_permissions' tool on the MCP server, including name, description, schema, and handler.
    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) }] };
      }
    );

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