generated from lucxjo/template
(#3) Now has a basic thread menu.
Closes #3 Signed-off-by: Louis Hollingworth <louis@hollingworth.ch>
This commit is contained in:
parent
6770bd8d35
commit
715d04ef9b
|
@ -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
33
src/commands/threads.ts
Normal 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 })
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue