Skip to main content
Glama

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
NameRequiredDescriptionDefault
guildIdYesThe ID of the server (guild)
userIdYesThe ID of the user to ban
deleteMessageSecondsNoNumber of seconds of messages to delete (0-604800)
reasonNoReason for the ban

Implementation Reference

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

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