Skip to main content
Glama

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
NameRequiredDescriptionDefault
guildIdYesThe ID of the server (guild)
channelIdYesThe ID of the parent channel
archivedNoInclude archived threads (default false)

Implementation Reference

  • 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) }] }; } );
  • 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) }] }; }
  • 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);

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