list_threads
Retrieve all threads within a Discord channel to manage discussions and organize conversations effectively.
Instructions
List all threads in a channel
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| guildId | Yes | The ID of the server (guild) | |
| channelId | Yes | The ID of the parent channel | |
| archived | No | Include archived threads (default false) |
Implementation Reference
- src/tools/thread-tools.ts:9-56 (registration)Registration of the 'list_threads' tool, including description, input schema using Zod, and the complete inline handler function that fetches threads from a Discord channel using discord.js.server.tool( 'list_threads', 'List all threads in a channel', { guildId: z.string().describe('The ID of the server (guild)'), channelId: z.string().describe('The ID of the parent channel'), archived: z.boolean().optional().describe('Include archived threads (default false)'), }, async ({ guildId, channelId, archived = false }) => { const result = await withErrorHandling(async () => { const client = await getDiscordClient(); const guild = await client.guilds.fetch(guildId); const channel = await guild.channels.fetch(channelId); if (!channel || (channel.type !== ChannelType.GuildText && channel.type !== ChannelType.GuildAnnouncement && channel.type !== ChannelType.GuildForum)) { throw new Error('Channel does not support threads'); } const threadChannel = channel as TextChannel | NewsChannel | ForumChannel; const threads = archived ? await threadChannel.threads.fetchArchived() : await threadChannel.threads.fetchActive(); return threads.threads.map((thread) => ({ id: thread.id, name: thread.name, type: ChannelType[thread.type], parentId: thread.parentId, ownerId: thread.ownerId, archived: thread.archived, locked: thread.locked, autoArchiveDuration: thread.autoArchiveDuration, messageCount: thread.messageCount, memberCount: thread.memberCount, createdAt: thread.createdAt?.toISOString(), archiveTimestamp: thread.archiveTimestamp ? new Date(thread.archiveTimestamp).toISOString() : null, })); }); 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:17-55 (handler)The core handler logic for list_threads: fetches guild and channel, validates channel type, fetches active or archived threads, maps to structured data, handles errors with withErrorHandling, and returns JSON stringified response.async ({ guildId, channelId, archived = false }) => { const result = await withErrorHandling(async () => { const client = await getDiscordClient(); const guild = await client.guilds.fetch(guildId); const channel = await guild.channels.fetch(channelId); if (!channel || (channel.type !== ChannelType.GuildText && channel.type !== ChannelType.GuildAnnouncement && channel.type !== ChannelType.GuildForum)) { throw new Error('Channel does not support threads'); } const threadChannel = channel as TextChannel | NewsChannel | ForumChannel; const threads = archived ? await threadChannel.threads.fetchArchived() : await threadChannel.threads.fetchActive(); return threads.threads.map((thread) => ({ id: thread.id, name: thread.name, type: ChannelType[thread.type], parentId: thread.parentId, ownerId: thread.ownerId, archived: thread.archived, locked: thread.locked, autoArchiveDuration: thread.autoArchiveDuration, messageCount: thread.messageCount, memberCount: thread.memberCount, createdAt: thread.createdAt?.toISOString(), archiveTimestamp: thread.archiveTimestamp ? new Date(thread.archiveTimestamp).toISOString() : null, })); }); 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:12-16 (schema)Input schema defined using Zod for parameters: guildId, channelId, and optional archived flag.{ guildId: z.string().describe('The ID of the server (guild)'), channelId: z.string().describe('The ID of the parent channel'), archived: z.boolean().optional().describe('Include archived threads (default false)'), },
- src/index.ts:64-64 (registration)Invocation of registerThreadTools(server) in the MCP server creation, which registers the list_threads tool among other thread management tools.registerThreadTools(server);