-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.js
65 lines (54 loc) · 2.03 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
const Discord = require('discord.js');
const mongo = require('mongodb').MongoClient
const fetch = require('node-fetch');
const fs = require('fs');
const config = require('./config.json')
const util = require('./utility.js')
const dburl = process.env.dbconnection
const client = new Discord.Client();
client.commands = new Discord.Collection();
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
var db, collection, command
for (const file of commandFiles) {
command = require(`./commands/${file}`);
client.commands.set(command.name, command);
}
mongo.connect(dburl, {
useNewUrlParser: true
}, (err, dbClient) => {
if (err) {
console.error(err)
return
}
db = dbClient.db('discordbot')
collection = db.collection('piclinks')
})
client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}!`);
client.user.setActivity("w!help -> commands")
});
client.on('INTERACTION_CREATE', async interaction => {
if (!interaction.isCommand()) return;
if (interaction.commandName === 'first') await interaction.reply('This is my first slash command! More to come soon...');
});
//command handling
client.on('message', async msg => {
var flag = util.initChecks(msg, client, collection);
if (flag) return;
//Remove the prefix from the command and split the commands into seperate arguments
const args = msg.content.slice(config.prefix.length).split(/ +/);
command = args.shift().toLowerCase();
//initiate dynamic command handling
if (config.users.includes(command)) {
client.commands.get('namepic').execute(msg, args, command)
} else {
try {
client.commands.get(command).execute(msg, args);
} catch (error) {
console.log(error)
msg.reply('there was an error trying to execute that command! That command may not exist, you may have entered the command incorrectly, or the bot is having issues. \nIf you are trying to set your color, the format is: w!setcolor AABBCC');
}
}
});
//client.login(''); Used for local hosting
client.login(process.env.BOT_TOKEN);