(#3) Now has a basic thread menu.

Closes #3

Signed-off-by: Louis Hollingworth <louis@hollingworth.ch>
This commit is contained in:
Louis Hollingworth 2023-06-15 18:32:49 +01:00
parent 6770bd8d35
commit 715d04ef9b
Signed by: lucxjo
GPG key ID: A11415CB3DC7809B
2 changed files with 33 additions and 10 deletions

View file

@ -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!");
}
}

33
src/commands/threads.ts Normal file
View file

@ -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 })
}
}
}