-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
69 lines (56 loc) · 2.27 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
67
68
69
require('dotenv').config();
const { prefix, token } = require("./config.json");
const { Client, GatewayIntentBits, Collection } = require('discord.js');
const parser = require('./utils/parser.js');
const bot = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.MessageContent
]
});
const fs = require("fs");
bot.commands = new Collection();
const commandFiles = fs.readdirSync('./commands/').filter(f => f.endsWith('.js'))
for (const file of commandFiles) {
const props = require(`./commands/${file}`)
console.log(`${file} loaded`)
bot.commands.set(props.config.name, props)
}
const commandSubFolders = fs.readdirSync('./commands/').filter(f => !f.endsWith('.js'))
commandSubFolders.forEach(folder => {
const commandFiles = fs.readdirSync(`./commands/${folder}/`).filter(f => f.endsWith('.js'))
for (const file of commandFiles) {
const props = require(`./commands/${folder}/${file}`)
console.log(`${file} loaded from ${folder}`)
bot.commands.set(props.config.name, props)
}
});
// Load Event files from events folder
const eventFiles = fs.readdirSync('./events/').filter(f => f.endsWith('.js'))
for (const file of eventFiles) {
const event = require(`./events/${file}`)
if (event.once) {
bot.once(event.name, (...args) => event.execute(...args, bot))
} else {
bot.on(event.name, (...args) => event.execute(...args, bot))
}
}
//Command Manager
bot.on("messageCreate", async message => {
// console.log(message);
//Check if author is a bot or the message was sent in dms and return
if (message.author.bot) return;
if (message.channel.type === "dm") return;
//get prefix from config and prepare message so it can be read as a command
let messageArray = message.content.split(" ");
let cmd = messageArray[0];
let args = messageArray.slice(1);
//Check for prefix
if (!cmd.startsWith(prefix)) return;
//Get the command from the commands collection and then if the command is found run the command file
let commandfile = bot.commands.get(cmd.slice(prefix.length));
if (commandfile) commandfile.run(bot, message, args);
});
bot.login(process.env.DISCORD_BOT_TOKEN);