From 715d04ef9bbf0d0b9effd59f45d1008b224ed12f Mon Sep 17 00:00:00 2001 From: Louis Hollingworth Date: Thu, 15 Jun 2023 18:32:49 +0100 Subject: [PATCH] (#3) Now has a basic thread menu. Closes #3 Signed-off-by: Louis Hollingworth --- src/commands/slashes.ts | 10 ---------- src/commands/threads.ts | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 10 deletions(-) delete mode 100644 src/commands/slashes.ts create mode 100644 src/commands/threads.ts 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 }) + } + } +}