add_role
Assign a specific Discord role to a user by specifying the server ID, user ID, and role ID. Simplifies role management within Discord servers for MCP clients.
Instructions
Add a role to a user
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| role_id | Yes | Role ID to add | |
| server_id | Yes | Discord server ID | |
| user_id | Yes | User to add role to |
Implementation Reference
- src/discord_mcp/server.py:516-525 (handler)Handler function for the 'add_role' tool. Fetches the guild, member, and role using the provided IDs, then adds the role to the member with a reason.elif name == "add_role": 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"])) await member.add_roles(role, reason="Role added via MCP") return [TextContent( type="text", text=f"Added role {role.name} to user {member.name}" )]
- src/discord_mcp/server.py:113-134 (registration)Registration of the 'add_role' tool via the list_tools() decorator. Defines the tool name, description, and input schema requiring server_id, user_id, and 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"] } ),