-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
index.js
executable file
·72 lines (60 loc) · 2.48 KB
/
index.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
const Discord = require('discord.js');
const fs = require('fs');
const client = new Discord.Client();
client.commands = new Discord.Collection();
global.client = client
process.on('unhandledRejection', error => {
console.log(`UnhandledPromiseRejection : ${error}\n`)
});
client.on('ready', async () => {
console.log(`\nLogged in : ${client.user.tag}\n`)
client.user.setActivity(`Slash!`, { type: "PLAYING" })
.then((presense) => console.log(`Set presense : ${presense.activities[0]}\n`))
.catch(console.error);
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const command = require(`./commands/${file}`);
client.api.applications(client.user.id).guilds('749595288280498188').commands.post({ data: {
name: command.name,
description: command.description,
options: command.commandOptions
}})
if (command.global == true) {
client.api.applications(client.user.id).commands.post({ data: {
name: command.name,
description: command.description,
options: command.commandOptions
}})
}
client.commands.set(command.name, command);
console.log(`Command POST : ${command.name} from ${file} (${command.global ? "global" : "guild"})`)
}
console.log("")
let cmdArrGlobal = await client.api.applications(client.user.id).commands.get()
let cmdArrGuild = await client.api.applications(client.user.id).guilds('749595288280498188').commands.get()
cmdArrGlobal.forEach(element => {
console.log("Global command loaded : " + element.name + " (" + element.id + ")" )
});
console.log("")
cmdArrGuild.forEach(element => {
console.log("Guild command loaded : " + element.name + " (" + element.id + ")")
});
console.log("")
});
client.ws.on('INTERACTION_CREATE', async interaction => {
if (!client.commands.has(interaction.data.name)) return;
try {
client.commands.get(interaction.data.name).execute(interaction);
} catch (error) {
console.log(`Error from command ${interaction.data.name} : ${error.message}`);
console.log(`${error.stack}\n`)
client.api.interactions(interaction.id, interaction.token).callback.post({data: {
type: 4,
data: {
content: `Sorry, there was an error executing that command!`
}
}
})
}
})
client.login(process.env.TOKEN);