Skip to main content
Glama
scarecr0w12

discord-mcp

list_bans

Retrieve a list of all banned users in a Discord server by providing the server ID to manage moderation actions and review server security.

Instructions

List all banned users in a server

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
guildIdYesThe ID of the server (guild)

Implementation Reference

  • Registration of the 'list_bans' tool using server.tool(). Includes inline input schema (guildId) and handler function that fetches all bans from the Discord guild using guild.bans.fetch(), maps them to {userId, username, reason}, handles errors with withErrorHandling, and returns JSON stringified response.
    // List bans
    server.tool(
      'list_bans',
      'List all banned users in a 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 bans = await guild.bans.fetch();
    
          return bans.map((ban) => ({
            userId: ban.user.id,
            username: ban.user.username,
            reason: ban.reason,
          }));
        });
    
        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_bans tool: requires guildId (string). Uses Zod for validation.
    {
      guildId: z.string().describe('The ID of the server (guild)'),
    },
  • Handler function for list_bans: fetches Discord client and guild, retrieves bans, formats output with userId, username, reason; wraps in withErrorHandling and returns MCP-formatted response.
    async ({ guildId }) => {
      const result = await withErrorHandling(async () => {
        const client = await getDiscordClient();
        const guild = await client.guilds.fetch(guildId);
        const bans = await guild.bans.fetch();
    
        return bans.map((ban) => ({
          userId: ban.user.id,
          username: ban.user.username,
          reason: ban.reason,
        }));
      });
    
      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:56-56 (registration)
    High-level registration call to registerMemberTools(server), which includes the list_bans tool among member management tools.
    registerMemberTools(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