-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
49 lines (37 loc) · 1.43 KB
/
Copy pathserver.js
File metadata and controls
49 lines (37 loc) · 1.43 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
require('dotenv').config();
const Discord = require('discord.js');
const CommandHandler = require('./CommandHandler.js');
const client = new Discord.Client({ intents: [Discord.GatewayIntentBits.Guilds, Discord.GatewayIntentBits.GuildMessages] });
const rest = new Discord.REST({ version: '10' }).setToken(process.env.TOKEN);
const ch = new CommandHandler();
ch.genCommandList();
client.once(Discord.Events.ClientReady, c => {
console.log(`Ready! Logged in as ${c.user.tag}`);
ch.init(rest, client.application.id);
client.commands = new Discord.Collection();
ch.orig_commands.forEach(cmd => {
client.commands.set(cmd.data.name, cmd);
})
});
client.login(process.env.TOKEN);
client.on('messageCreate', msg => {
// console.log(msg);
});
client.on(Discord.Events.InteractionCreate, async interaction => {
if (!interaction.isChatInputCommand()) return;
const command = interaction.client.commands.get(interaction.commandName);
if (!command) {
console.error(`No command matching ${interaction.commandName} was found.`);
return;
}
try {
await command.execute(interaction);
} catch (error) {
console.error(error);
if (interaction.replied || interaction.deferred) {
await interaction.followUp({ content: 'There was an error while executing this command!', ephemeral: true });
} else {
await interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true });
}
}
});