diff --git a/src/commands/slashes.ts b/src/commands/slashes.ts deleted file mode 100644 index a23a5a8..0000000 --- a/src/commands/slashes.ts +++ /dev/null @@ -1,10 +0,0 @@ -import type { CommandInteraction } from "discord.js"; -import { Discord, Slash } from "discordx"; - -@Discord() -export class Example { - @Slash({ description: "ping" }) - ping(interaction: CommandInteraction): void { - interaction.reply("pong!"); - } -} diff --git a/src/commands/threads.ts b/src/commands/threads.ts new file mode 100644 index 0000000..cd00e28 --- /dev/null +++ b/src/commands/threads.ts @@ -0,0 +1,33 @@ +import { CommandInteraction } from "discord.js"; +import { Discord, Slash } from "discordx"; + +@Discord() +export class Threads { + @Slash({ description: "Display current threads", name: "threads" }) + async threads(interaction: CommandInteraction) { + if (interaction.guild) { + const threads = await fetch(`https://discord.com/api/v10/guilds/${interaction.guildId}/threads/active`, { + headers: { + "Content-Type": "application/json", + "Authorization": `Bot ${process.env.DISCORD_TOKEN}` + } + }) + + + const body = (await threads.json()).threads as Array<{ + flags: number, + guild_id: string, + id: string, + parent_id: string + }>; + + let threadMsg = "The current active threads are:" + + body.forEach((thread) => { + threadMsg += `\n- <#${thread.id}>` + }) + + interaction.reply({ content: threadMsg, ephemeral: true }) + } + } +}