-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
66 lines (52 loc) · 1.93 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
55
56
57
58
59
60
61
62
63
64
65
66
// Import necessary libraries
const { Client, GatewayIntentBits, Collection } = require('discord.js');
const fs = require('fs');
require('dotenv').config();
// Create a new Discord client with the specified intents
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent // This line is crucial
]
});
// Command collection
client.commands = new Collection();
// Load commands
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const command = require(`./commands/${file}`);
client.commands.set(command.name, command);
}
// Load events
const eventFiles = fs.readdirSync('./events').filter(file => file.endsWith('.js'));
for (const file of eventFiles) {
const event = require(`./events/${file}`);
if (event.once) {
client.once(event.name, (...args) => event.execute(...args, client));
} else {
client.on(event.name, (...args) => event.execute(...args, client));
}
}
// Message listener for commands
client.on('messageCreate', message => {
console.log(`Received message: ${message.content}`);
if (!message.content.startsWith('!') || message.author.bot) return;
const args = message.content.slice(1).trim().split(/ +/);
const commandName = args.shift().toLowerCase();
if (!client.commands.has(commandName)) return;
const command = client.commands.get(commandName);
try {
command.execute(message, args);
} catch (error) {
console.error(error);
message.reply('There was an error trying to execute that command!');
}
});
for (const file of commandFiles) {
const command = require(`./commands/${file}`);
console.log(`Loading command: ${command.name}`);
client.commands.set(command.name, command);
}
// Login to Discord with your app's token
client.login(process.env.DISCORD_TOKEN);