-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbot.js
44 lines (36 loc) · 1.32 KB
/
bot.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
const Discord = require("discord.js");
const fs = require("fs");
const bot = new Discord.Client({disableEveryone: true});
bot.commands = new Discord.Collection();
const config = require("./config.json");
bot.login(config.token).then(function() {
console.log(`Connected to discord and logged in as ${bot.user.tag}`)
}).catch((e) => {
console.log(e)
})
bot.on('ready', async() => {
bot.user.setActivity(config.game)
});
fs.readdir('./commands', (err, files) => {
if (err) console.log(err)
let jsfile = files.filter(f => f.split(".").pop() === "js")
if (jsfile.length <= 0) {
console.log('No commands have been found why not make some!')
return;
}
jsfile.forEach((file, i) => {
let props = require(`./commands/${file}`)
console.log(`${file} has been loaded`)
bot.commands.set(props.help.name, props)
})
bot.on('message', async message => {
let prefix = config.prefix
if (!message.content.startsWith(prefix)) return
if (message.author.bot || message.channel.type === "dm") return
let messageArray = message.content.split(' ')
let cmd = messageArray[0]
let args = messageArray.splice(1)
let commandFile = bot.commands.get(cmd.slice(prefix.length))
if (commandFile) commandFile.run(bot, message, args)
})
})