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
| Name | Required | Description | Default |
|---|---|---|---|
| guildId | Yes | The ID of the server (guild) |
Implementation Reference
- src/tools/member-tools.ts:235-261 (registration)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) }] }; } );
- src/tools/member-tools.ts:239-241 (schema)Input schema for list_bans tool: requires guildId (string). Uses Zod for validation.{ guildId: z.string().describe('The ID of the server (guild)'), },
- src/tools/member-tools.ts:242-260 (handler)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);