delete_role
Remove a role from a Discord server by specifying the server and role IDs. This tool helps manage server permissions and organization by eliminating unnecessary roles.
Instructions
Delete a role from a Discord server
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| guildId | Yes | The ID of the server (guild) | |
| roleId | Yes | The ID of the role to delete | |
| reason | No | Reason for deleting the role |
Implementation Reference
- src/tools/role-tools.ts:130-156 (handler)Full implementation of the 'delete_role' MCP tool: registers the tool with input schema (guildId, roleId, optional reason), fetches Discord guild and role, deletes the role if found, wraps in error handling, and returns JSON response.server.tool( 'delete_role', 'Delete a role from a Discord server', { guildId: z.string().describe('The ID of the server (guild)'), roleId: z.string().describe('The ID of the role to delete'), reason: z.string().optional().describe('Reason for deleting the role'), }, async ({ guildId, roleId, reason }) => { const result = await withErrorHandling(async () => { const client = await getDiscordClient(); const guild = await client.guilds.fetch(guildId); const role = await guild.roles.fetch(roleId); if (!role) throw new Error('Role not found'); const roleName = role.name; await role.delete(reason); return { roleId, roleName, message: 'Role deleted 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/role-tools.ts:133-137 (schema)Zod input schema for delete_role tool parameters.{ guildId: z.string().describe('The ID of the server (guild)'), roleId: z.string().describe('The ID of the role to delete'), reason: z.string().optional().describe('Reason for deleting the role'), },
- src/index.ts:56-56 (registration)Registers all role tools including delete_role by calling registerRoleTools on the MCP server instance.registerRoleTools(server);
- src/index.ts:14-14 (registration)Imports the registerRoleTools function used to register the delete_role tool.import { registerRoleTools } from './tools/role-tools.js';