-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
63 lines (50 loc) · 1.66 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
// Set up bot 🦠
const { Client, Collection } = require("discord.js")
const bot = new Client()
const { prefix, token } = require("./config")
// Break up bot into multiple files 💔
const fs = require("fs")
// Set new commands 💬
bot.commands = new Collection()
// Let's us know bot is online 🍏
bot.on("ready", () => {
console.log("FireBot is live!")
bot.user.setActivity("with fire!")
})
// Set up event file directories 🌄
const eventFiles = fs
.readdirSync("./events")
.filter((file) => file.endsWith(".js"))
for (const file of eventFiles) {
const event = require(`./events/${file}`)
console.log(`Loaded event: ${event.name}`)
if (event.once) {
bot.once(event.name, (...args) => event.execute(...args, bot))
} else {
bot.on(event.name, (...args) => event.execute(...args, bot))
}
}
const commandFiles = fs
.readdirSync("./commands")
.filter((file) => file.endsWith(".js"))
for (const file of commandFiles) {
const command = require(`./commands/${file}`)
// set a new item in the Collection
// with the key as the command name and the value as the exported module
bot.commands.set(command.name, command)
console.log("Loaded command:", command.name)
}
bot.on("message", (message) => {
if (!message.content.startsWith(prefix) || message.author.bot) return
const args = message.content.slice(prefix.length).trim().split(/ +/)
const command = args.shift().toLowerCase()
if (!bot.commands.has(command)) return
try {
bot.commands.get(command).execute(message, args)
} catch (error) {
console.error(error)
message.reply("there was an error trying to execute that command!")
}
})
// Login bot 🌳
bot.login(token)