This repository was archived by the owner on Jun 2, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
87 lines (73 loc) · 2.55 KB
/
Copy pathapp.js
File metadata and controls
87 lines (73 loc) · 2.55 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
//#region libs
require('dotenv').config();
const fs = require('fs');
//Discord Lib
const { Client, Collection, Intents, } = require('discord.js');
const beyondIntents = new Intents();
beyondIntents.add(
Intents.FLAGS.GUILDS,
Intents.FLAGS.GUILD_MEMBERS,
Intents.FLAGS.GUILD_MESSAGES,
Intents.FLAGS.GUILD_PRESENCES,
Intents.FLAGS.DIRECT_MESSAGES,
Intents.FLAGS.DIRECT_MESSAGE_REACTIONS);
const bot = new Client({ intents: beyondIntents, partials: ["CHANNEL"] });
//Trace Module
const {err, wrn, inf, not, dbg} = require('./trace.js');
//#endregion
//#region Event Handling
const eventFiles = fs.readdirSync('./events').filter(file => file.endsWith('.js'));
for (const file of eventFiles) {
const event = require(`./events/${file}`);
if (event.once) {
bot.once(event.name, (...args) => event.execute(...args));
} else {
bot.on(event.name, (...args) => event.execute(...args));
}
}
//#endregion
//#region Command handling
bot.commands = new Collection();
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
const destinyCommandFiles = fs.readdirSync('./commands/destiny').filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const command = require(`./commands/${file}`);
bot.commands.set(command.data.name, command);
}
for (const file of destinyCommandFiles) {
const command = require(`./commands/destiny/${file}`);
bot.commands.set(command.data.name, command);
}
bot.on ('interactionCreate', async interaction => {
if (!interaction.isCommand()) return; //Is the message a command ?
if(interaction.channel.type === "DM") return;
if (interaction.user.bot) return; //Is the user a bot ?
const command = bot.commands.get(interaction.commandName);
if (!command) return;
// Bot latency check
if(command.data.name === 'ping') {
try {
await command.execute(interaction, bot);
} catch (error) {
err(error);
await interaction.reply({
content: 'The command couldn\'t be executed due to an error.',
ephemeral: true
});
}
} else {
try {
await command.execute(interaction);
} catch (error) {
err(error);
await interaction.editReply({
content: 'The command couldn\'t be executed due to an error.',
ephemeral: true
});
}
}
});
//#endregion
bot.login(process.env.DISCORD_TOKEN).catch( error => {
err("Can't log Beyond Bot : ", error);
});