add_role
Assign a Discord role to a user by specifying user ID and role ID. Manage server permissions and organize members through role-based access control.
Instructions
Add a role to a Discord user.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| user_id | Yes | ||
| role_id | Yes | ||
| server_id | No | ||
| reason | No |
Implementation Reference
- The static async method `handle_add_role` in `CoreToolHandlers` class that implements the core logic: fetches guild/member/role and adds the role using Discord API.@staticmethod async def handle_add_role(discord_client, arguments: Dict[str, Any]) -> List[TextContent]: """Add a role to 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.add_roles(role, reason="Role added via MCP") return [TextContent( type="text", text=f"Added role '{role.name}' to {member.display_name} in {guild.name}" )]
- The Tool definition including name, description, and inputSchema for 'add_role' parameters: server_id, user_id, role_id.Tool( name="add_role", description="Add a role to a user", inputSchema={ "type": "object", "properties": { "server_id": { "type": "string", "description": "Discord server ID" }, "user_id": { "type": "string", "description": "User to add role to" }, "role_id": { "type": "string", "description": "Role ID to add" } }, "required": ["server_id", "user_id", "role_id"] } ),
- src/discord_mcp/integrated_server.py:1021-1032 (registration)The dispatch registration in `call_tool` function: includes 'add_role' in `core_tool_names` list and dynamically calls `CoreToolHandlers.handle_add_role`.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)