ban_member
Remove a user from a Discord server to enforce rules and maintain community safety. Specify the server, user, message deletion period, and reason for the action.
Instructions
Ban a member from the server
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| guildId | Yes | The ID of the server (guild) | |
| userId | Yes | The ID of the user to ban | |
| deleteMessageSeconds | No | Number of seconds of messages to delete (0-604800) | |
| reason | No | Reason for the ban |
Implementation Reference
- src/tools/member-tools.ts:186-206 (handler)The handler function for the 'ban_member' tool. It fetches the Discord guild, applies ban options (delete message seconds clamped to 0-7 days, reason), bans the user via guild.members.ban, and returns success/error response.async ({ guildId, userId, deleteMessageSeconds, reason }) => { const result = await withErrorHandling(async () => { const client = await getDiscordClient(); const guild = await client.guilds.fetch(guildId); const banOptions: { deleteMessageSeconds?: number; reason?: string } = {}; if (deleteMessageSeconds !== undefined) { banOptions.deleteMessageSeconds = Math.min(Math.max(0, deleteMessageSeconds), 604800); } if (reason) banOptions.reason = reason; await guild.members.ban(userId, banOptions); return { userId, message: 'User banned successfully' }; }); 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:180-184 (schema)Zod input schema defining parameters for the ban_member tool: guildId (required), userId (required), deleteMessageSeconds (optional), reason (optional).{ guildId: z.string().describe('The ID of the server (guild)'), userId: z.string().describe('The ID of the user to ban'), deleteMessageSeconds: z.number().optional().describe('Number of seconds of messages to delete (0-604800)'), reason: z.string().optional().describe('Reason for the ban'),
- src/tools/member-tools.ts:177-207 (registration)Registration of the 'ban_member' tool using server.tool(), including description, input schema, and inline handler function.server.tool( 'ban_member', 'Ban a member from the server', { guildId: z.string().describe('The ID of the server (guild)'), userId: z.string().describe('The ID of the user to ban'), deleteMessageSeconds: z.number().optional().describe('Number of seconds of messages to delete (0-604800)'), reason: z.string().optional().describe('Reason for the ban'), }, async ({ guildId, userId, deleteMessageSeconds, reason }) => { const result = await withErrorHandling(async () => { const client = await getDiscordClient(); const guild = await client.guilds.fetch(guildId); const banOptions: { deleteMessageSeconds?: number; reason?: string } = {}; if (deleteMessageSeconds !== undefined) { banOptions.deleteMessageSeconds = Math.min(Math.max(0, deleteMessageSeconds), 604800); } if (reason) banOptions.reason = reason; await guild.members.ban(userId, banOptions); return { userId, message: 'User banned successfully' }; }); if (!result.success) { return { content: [{ type: 'text', text: result.error }], isError: true }; } return { content: [{ type: 'text', text: JSON.stringify(result.data, null, 2) }] }; } );