This repository has been archived by the owner on Jul 14, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathapp.js
54 lines (49 loc) · 1.4 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
const { Client, APIMessage } = require("discord.js");
const { readdirSync } = require("fs");
const Bot = new Client();
const Config = require("./config");
const Commands = [];
const cmdFiles = readdirSync("./commands").filter((file) =>
file.endsWith(".js"),
);
Bot.on("ready", async () => {
for (const fileName of cmdFiles) {
const File = require(`./commands/${fileName}`);
Commands.push(File);
await Bot.api.applications(Bot.user.id).commands.post({
data: {
name: File.name,
description: File.description,
options: File.options,
},
});
}
console.info(`Logged in as ${Bot.user.username}`);
});
Bot.ws.on("INTERACTION_CREATE", (interaction) => {
const CMDFile = Commands.find(
(cmd) => cmd.name.toLowerCase() === interaction.data.name.toLowerCase(),
);
if (CMDFile)
CMDFile.execute(Bot, say, interaction, interaction.data.options);
});
Bot.login(Config.token);
async function say(interaction, content) {
return Bot.api
.interactions(interaction.id, interaction.token)
.callback.post({
data: {
type: 4,
data: await createAPIMessage(interaction, content),
},
});
}
async function createAPIMessage(interaction, content) {
const apiMessage = await APIMessage.create(
Bot.channels.resolve(interaction.channel_id),
content,
)
.resolveData()
.resolveFiles();
return { ...apiMessage.data, files: apiMessage.files };
}