-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
70 lines (55 loc) · 1.82 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
const { Client, GatewayIntentBits, Collection, ActivityType } = require('discord.js');
const { config } = require('dotenv');
const fs = require('fs');
config();
const bot = new Client({
intents: [
GatewayIntentBits.Guilds,
],
});
bot.commands = new Collection();
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
try {
const command = require(`./commands/${file}`);
bot.commands.set(command.data.name, command);
console.log(`Loaded command: ${command.data.name}`);
} catch (error) {
console.error(`Error loading command file '${file}':`);
console.error(error.stack);
}
}
bot.once('ready', async () => {
try {
console.log(`Logged in as ${bot.user.tag}!`);
bot.user.setPresence({
activities: [{
name: "Made by Larssies",
type: ActivityType.Custom,
url: 'https://larssies.com'
}],
})
bot.commands.forEach(async command => {
await bot.application.commands.create(command.data);
});
} catch (error) {
console.log(`Error during bot setup: ${error.message}`, 'error');
}
});
bot.on('interactionCreate', async (interaction) => {
try {
if (!interaction.isCommand() && !interaction.isStringSelectMenu() && !interaction.isButton() && !interaction.isModalSubmit()) {
return;
}
console.log(`Interaction type: ${interaction.type}`);
if (interaction.isCommand()) {
const { commandName } = interaction;
console.log(`Command executed: ${commandName}`);
if (!bot.commands.has(commandName)) return;
await bot.commands.get(commandName).execute(interaction);
}
} catch (error) {
console.log(`Error handling interaction: ${error.message}`, 'error');
}
});
bot.login(process.env.BOT_TOKEN);