Skip to main content
Glama

list_roles

Retrieve all role names and IDs from a Discord server using the server's guild ID to manage permissions and member assignments.

Instructions

List all roles in a Discord server

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
guildIdYesThe ID of the server (guild)

Implementation Reference

  • Executes the list_roles tool: fetches Discord guild roles using discord.js, extracts key properties (id, name, color, position, hoist, mentionable, managed, permissions array, member count), sorts by descending position, handles errors with withErrorHandling, and returns JSON-formatted list or error.
    async ({ guildId }) => { const result = await withErrorHandling(async () => { const client = await getDiscordClient(); const guild = await client.guilds.fetch(guildId); const roles = await guild.roles.fetch(); return roles.map((role) => ({ id: role.id, name: role.name, color: role.hexColor, position: role.position, hoist: role.hoist, mentionable: role.mentionable, managed: role.managed, permissions: role.permissions.toArray(), memberCount: role.members.size, })).sort((a, b) => b.position - a.position); }); if (!result.success) { return { content: [{ type: 'text', text: result.error }], isError: true }; } return { content: [{ type: 'text', text: JSON.stringify(result.data, null, 2) }] }; } );
  • Input schema for list_roles tool: requires 'guildId' as a string, described as the ID of the server (guild). Uses Zod for validation.
    { guildId: z.string().describe('The ID of the server (guild)'), },
  • Registers the 'list_roles' tool on the MCP server with name, description, input schema (guildId), and inline handler function.
    server.tool( 'list_roles', 'List all roles in a Discord server', { guildId: z.string().describe('The ID of the server (guild)'), }, async ({ guildId }) => { const result = await withErrorHandling(async () => { const client = await getDiscordClient(); const guild = await client.guilds.fetch(guildId); const roles = await guild.roles.fetch(); return roles.map((role) => ({ id: role.id, name: role.name, color: role.hexColor, position: role.position, hoist: role.hoist, mentionable: role.mentionable, managed: role.managed, permissions: role.permissions.toArray(), memberCount: role.members.size, })).sort((a, b) => b.position - a.position); }); 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