leave_thread
Remove a Discord bot from a specific thread by providing the server and thread IDs to manage bot participation.
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)Executes the leave_thread tool: fetches the guild and thread, validates it is a thread, calls thread.leave(), handles errors, 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)Registers the 'leave_thread' tool on the MCP server using server.tool() with name, description, 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) }] }; } );