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
| Name | Required | Description | Default |
|---|---|---|---|
| guildId | Yes | The ID of the server (guild) | |
| threadId | Yes | The ID of the thread |
Implementation Reference
- src/tools/thread-tools.ts:311-331 (handler)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) }] }; }
- src/tools/thread-tools.ts:307-310 (schema)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'), },
- src/tools/thread-tools.ts:304-332 (registration)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);