Skip to main content
Glama
scarecr0w12

discord-mcp

delete_thread

Remove a Discord thread from a server by specifying the guild and thread IDs. This tool helps manage server organization by deleting outdated or unnecessary discussion threads.

Instructions

Delete a thread

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
guildIdYesThe ID of the server (guild)
threadIdYesThe ID of the thread to delete
reasonNoReason for deleting

Implementation Reference

  • The handler function that executes the delete_thread tool: fetches the guild and thread, deletes the thread with optional reason, handles errors with withErrorHandling, and returns success/error response.
    async ({ guildId, threadId, reason }) => {
      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');
        }
    
        const threadName = thread.name;
        await thread.delete(reason);
    
        return { threadId, threadName, message: 'Thread deleted successfully' };
      });
    
      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 using Zod for the delete_thread tool parameters.
    {
      guildId: z.string().describe('The ID of the server (guild)'),
      threadId: z.string().describe('The ID of the thread to delete'),
      reason: z.string().optional().describe('Reason for deleting'),
    },
  • Registration of the delete_thread tool on the MCP server using server.tool() including name, description, schema, and handler.
    server.tool(
      'delete_thread',
      'Delete a thread',
      {
        guildId: z.string().describe('The ID of the server (guild)'),
        threadId: z.string().describe('The ID of the thread to delete'),
        reason: z.string().optional().describe('Reason for deleting'),
      },
      async ({ guildId, threadId, reason }) => {
        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');
          }
    
          const threadName = thread.name;
          await thread.delete(reason);
    
          return { threadId, threadName, message: 'Thread deleted 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)
    Higher-level registration call that includes the delete_thread tool via registerThreadTools.
    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