-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
81 lines (55 loc) · 2.36 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
const fs = require('fs');
const { Client, Collection, GatewayIntentBits } = require('discord.js');
const { AudioPlayerManager } = require('./classes/audioplayermanager.js');
const { User } = require('./classes/user.js');
const { Interaction } = require('./classes/interaction.js');
const { token, prefix, operators } = require('./config.json');
const client = new Client({intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.GuildVoiceStates, GatewayIntentBits.MessageContent] });
client.commands = new Collection();
// Set up commands.
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const command = require(`./commands/${file}`);
client.commands.set(command.name, command);
command.aliases.forEach(alias => {
client.commands.set(alias, command);
});
}
// Audio Player Manager.
const audioPlayerManager = new AudioPlayerManager();
client.once('ready', () => {
console.log('RocBot is now online!');
});
client.on('interactionCreate', async interaction => {
if (!interaction.isCommand()) return;
const command = interaction.commandName.toLowerCase();
const args = [];
const user = User.load(interaction.user.id);
if (typeof interaction.options !== 'undefined') {
interaction.options._hoistedOptions.forEach(option => {
option.value.split(/\s+/).forEach(arg => {
args.push('' + arg);
});
});
}
execute(interaction, command, args, user);
});
client.on('messageCreate', (message) => {
if(!message.content.startsWith(prefix) || message.author.bot) return;
const args = message.content.slice(prefix.length).split(/\s+/);
const command = args.shift().toLowerCase();
const user = User.load(message.author.id);
execute(message, command, args, user);
});
client.login(token);
function execute(interaction, command, args, user) {
if (typeof client.commands.get(command) === 'undefined') {
return;
}
interaction = new Interaction(interaction);
if (client.commands.get(command).operatorOnly && !operators.includes(id)) {
interaction.send("You don't have sufficient permission to use this command");
return;
}
client.commands.get(command).execute(interaction, command, args, client, user, audioPlayerManager);
}