-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
72 lines (64 loc) · 2.86 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
64
65
66
67
68
69
70
71
72
require('dotenv').config();
const Discord = require('discord.js');
// require Nuggies package
const Nuggies = require('nuggies');
const client = new Discord.Client();
// require discord-buttons package
require('discord-buttons')(client);
const fs = require('fs');
// Connect to the database
Nuggies.connect(process.env.mongoURI);
// login to the bot
client.login(process.env.BOT_TOKEN);
Nuggies.handleInteractions(client);
client.commands = new Discord.Collection();
client.aliases = new Discord.Collection();
fs.readdir('./commands/', (err, files) => {
if (err) console.log(err);
const file = files.filter(f => f.split('.').pop() === 'js');
if (file.length < 1) {
console.log('No Commands.');
return;
}
file.forEach(f => {
const pull = require(`./commands/${f}`);
client.commands.set(pull.config.name, pull);
pull.config.aliases.forEach(aliases => client.aliases.set(aliases, pull.config.name));
});
});
client.on('message', async message => {
const prefix = '.'
if (message.author.bot || message.channel.type === 'dm') return;
if (message.content.startsWith(prefix)) {
const messageArray = message.content.split(' ');
const cmd = messageArray[0]
const args = messageArray.slice(1);
const command = client.commands.get(cmd.slice(prefix.length)) || client.commands.get(client.aliases.get(cmd.slice(prefix.length)));
if (command) {
if (!command.config.botPerms) return console.log("You didn't provide botPerms");
if (!Array.isArray(command.config.botPerms)) return console.log('botPerms must be an array.');
if (!command.config.userPerms) return console.log("You didn't provide userPerms.");
if (!Array.isArray(command.config.userPerms)) return console.log('userPerms must be an array.')
if (!message.guild.me.hasPermission(command.config.botPerms)) {
const beauty = command.config.botPerms.join('\`, \`');
const noBotPerms = new Discord.MessageEmbed()
.setTitle('Missing Permissions')
.setDescription(`I am missing these permissions: \`${beauty}\`.`)
.setColor('RED');
return message.channel.send(noBotPerms)
}
if (!message.member.hasPermission(command.config.userPerms)) {
const beauty = command.config.userPerms.join('\`, \`');
const noUserPerms = new Discord.MessageEmbed()
.setTitle('Missing Permissions')
.setDescription(`You are missing these permissions: \`${beauty}\`.`)
.setColor('RED');
return message.channel.send(noUserPerms)
}
command.run(client, message, args);
}
}
});
client.on('ready', () => {
console.log(`${client.user.username} is now ready!`);
});