Skip to main content
Glama
wowjinxy
by wowjinxy

remove_role

Remove a Discord role from a user by specifying user ID and role ID. This tool manages server permissions and member access within Discord communities.

Instructions

Remove a role from a Discord user.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
user_idYes
role_idYes
server_idNo
reasonNo

Implementation Reference

  • The handler function that implements the core logic for the 'remove_role' tool. It fetches the guild, member, and role using the provided IDs, checks if the role exists, removes the role from the member, and returns a confirmation message.
    @staticmethod
    async def handle_remove_role(discord_client, arguments: Dict[str, Any]) -> List[TextContent]:
        """Remove a role from a user"""
        guild = await discord_client.fetch_guild(int(arguments["server_id"]))
        member = await guild.fetch_member(int(arguments["user_id"]))
        role = guild.get_role(int(arguments["role_id"]))
        
        if not role:
            return [TextContent(type="text", text="Role not found")]
        
        await member.remove_roles(role, reason="Role removed via MCP")
        
        return [TextContent(
            type="text",
            text=f"Removed role '{role.name}' from {member.display_name} in {guild.name}"
        )]
  • Registers the 'remove_role' tool with the MCP server in the list_tools() function. Includes the tool name, description, and input schema defining required parameters: server_id, user_id, role_id.
    Tool(
        name="remove_role",
        description="Remove a role from a user",
        inputSchema={
            "type": "object",
            "properties": {
                "server_id": {
                    "type": "string",
                    "description": "Discord server ID"
                },
                "user_id": {
                    "type": "string",
                    "description": "User to remove role from"
                },
                "role_id": {
                    "type": "string",
                    "description": "Role ID to remove"
                }
            },
            "required": ["server_id", "user_id", "role_id"]
        }
    ),
  • In the call_tool handler, 'remove_role' is included in core_tool_names list, which routes the tool call to CoreToolHandlers.handle_remove_role for execution.
    core_tool_names = [
        "get_server_info", "list_servers", "get_channels", "list_members",
        "get_user_info", "send_message", "read_messages", "add_reaction",
        "add_multiple_reactions", "remove_reaction", "moderate_message",
        "create_text_channel", "delete_channel", "add_role", "remove_role"
    ]
    
    if name in core_tool_names:
        handler_method = f"handle_{name}"
        if hasattr(CoreToolHandlers, handler_method):
            return await getattr(CoreToolHandlers, handler_method)(discord_client, arguments)

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/wowjinxy/mcp-discord'

If you have feedback or need assistance with the MCP directory API, please join our Discord server