-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
98 lines (81 loc) · 3.44 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
require('dotenv').config();
const { Client, MessageEmbed, Collection } = require('discord.js');
const bot = new Client();
const fs = require('fs')
const prefix = process.env.PREFIX
// bot.commands as a collection(Map) of commands from ./commands
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
bot.commands = new Collection();
for (const file of commandFiles) {
const command = require(`./commands/${file}`);
bot.commands.set(command.name, command);
}
// --------------------------------------
//
// EVENT ON LOGIN
//
// --------------------------------------
bot.on('ready', () => {
// eslint-disable-next-line no-console
console.log(`Logged in as ${bot.user.username} ${prefix}`);
bot.user.setActivity(`${prefix}help`, { type: 'PLAYING' })
});
// --------------------------------------
//
// EVENT ON MESSAGE
//
// --------------------------------------
bot.on('message', async message => {
if (message.author.bot || !message.content.startsWith(prefix) || message.content === prefix)
return
// If it's a DM
if (message.channel.type === 'dm')
message.channel.send('I do not support DM commands.')
.then().catch(console.error)
// Command handling
const textStr = message.content.slice(prefix.length)
const commandName = textStr.split(/ +/).shift().toLowerCase();
const argsStr = textStr.slice(commandName.length + 1)
// Map all the commands
const command = bot.commands.get(commandName) || bot.commands.find(cmd => cmd.aliases && cmd.aliases.includes(commandName));
// Return if the command doesn't exist
if (!command || command.permsAllowed === undefined)
return
// const wickedbot = message.guild.channels.cache.get('696894142625742905')
// const proMatchmaking = message.guild.channels.cache.get('762784243155730492')
// const adminbot = message.guild.channels.cache.get('702447004105703424')
// const matchmaking = message.guild.channels.cache.get('558364419139043363')
// if (!(message.channel.id === wickedbot.id || message.channel.id === proMatchmaking.id || message.channel.id === adminbot.id || message.channel.id === matchmaking.id) && command.category !== 'Basic')
// return message.channel.send(`You need to be in ${wickedbot}, ${matchmaking}, ${proMatchmaking} or ${adminbot} to use this command of mine.`)
if (message.member.roles.cache.size < 1 && command.category !== 'Basic')
return message.channel.send('You need a player role to use the bot. Do a practice set then contact the Mods. Good luck!')
if (command.category === 'Staff' && message.member.roles.cache.has('829548653877657630') && message.author.id !== '217385992837922819')
return message.channel.send('Only an admin can use this command, sorry!')
const color = [
'#F32C48',
'#009348',
'#000002',
'#F9BB1E',
'#007FB7'
][Math.floor(Math.random() * 5)]
// Instantiate the embed that's sent to every command execution
const embed = new MessageEmbed().setColor(color)
try {
// EXECUTE COMMAND
const reply = await command.execute(message, argsStr, embed);
// if there's a reply, send it
if (reply)
message.channel.send(reply)
.then().catch(console.error)
return
} catch (error) {
// If error, log it and reply it
console.log(error.stack || error)
return message.channel.send(`${error}`)
.then().catch(console.error)
}
})
bot.on('error', error => {
console.error('ERROR', error.stack)
})
bot.login(process.env.TOKEN);