Skip to main content
Glama

leave_thread

Remove the bot from a Discord thread to stop receiving notifications and messages in that specific conversation channel.

Instructions

Make the bot leave a thread

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
guildIdYesThe ID of the server (guild)
threadIdYesThe ID of the thread

Implementation Reference

  • The async handler function for the leave_thread tool. Fetches the Discord guild and thread, verifies it's a thread channel, calls thread.leave(), handles errors with withErrorHandling, and returns formatted response.
    async ({ guildId, threadId }) => { const result = await withErrorHandling(async () => { const client = await getDiscordClient(); const guild = await client.guilds.fetch(guildId); const thread = await guild.channels.fetch(threadId); if (!thread || !thread.isThread()) { throw new Error('Thread not found'); } await thread.leave(); return { threadId, threadName: thread.name, message: 'Left thread successfully' }; }); if (!result.success) { return { content: [{ type: 'text', text: result.error }], isError: true }; } return { content: [{ type: 'text', text: JSON.stringify(result.data, null, 2) }] }; }
  • Zod input schema defining required parameters: guildId (server ID) and threadId.
    { guildId: z.string().describe('The ID of the server (guild)'), threadId: z.string().describe('The ID of the thread'), },
  • Direct registration of the leave_thread tool using server.tool() with name, description, input schema, and handler function.
    server.tool( 'leave_thread', 'Make the bot leave a thread', { guildId: z.string().describe('The ID of the server (guild)'), threadId: z.string().describe('The ID of the thread'), }, async ({ guildId, threadId }) => { const result = await withErrorHandling(async () => { const client = await getDiscordClient(); const guild = await client.guilds.fetch(guildId); const thread = await guild.channels.fetch(threadId); if (!thread || !thread.isThread()) { throw new Error('Thread not found'); } await thread.leave(); return { threadId, threadName: thread.name, message: 'Left thread 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/index.ts:64-64 (registration)
    Invocation of registerThreadTools(server) in the main MCP server setup, which registers the leave_thread tool among other thread tools.
    registerThreadTools(server);

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