-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathindex.js
64 lines (55 loc) · 2.1 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
Discord = require('discord.js');
fs = require('fs');
global.client = new Discord.Client({
messageCacheMaxSize: 1,
intents: [
Discord.GatewayIntentBits.Guilds,
Discord.GatewayIntentBits.GuildMessages,
Discord.GatewayIntentBits.GuildMembers,
Discord.GatewayIntentBits.GuildPresences,
Discord.GatewayIntentBits.DirectMessages,
],
partials: [
Discord.Partials.Channel
],
allowedMentions: { parse: ['users'], repliedUser: true }
});
const globals = require('./globals.js');
for (const [k, v] of Object.entries(globals)) global[k] = v;
const { token } = require('./token.json');
client.commands = new Discord.Collection();
global.commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const command = require(`./commands/${file}`);
client.commands.set(command.data.name, command);
}
// Interaction handler
client.on('interactionCreate', async interaction => {
// Slash commands
if (interaction.isChatInputCommand()) {
// Get local equivalent
const command = client.commands.get(interaction.commandName);
// Restrict owner only commands
if (command.ownerOnly && !owners.includes(interaction.user.id)) return interaction.reply('Only the bot owners can use this command!');
// Execute command
command.execute(interaction)
.then(log => { log ? sendLog(log) : sendLog(command.data.name + ' was used'); })
.catch(error => {
sendLog(
'<@&513807019048828929> there was an error!\n\nCommand:```' + command.data.name +
'```\nError' + (error.lineNumber ? ` (at line ${error.lineNumber}')` : '') + ':```' + error.message + '```');
console.error(error);
interaction.reply('there was an error trying to execute that command! You can report it here: ' + serverLink);
});
}
});
client.once('ready', () => {
if (client.user.id === '513515391155175424') sendLog('<@&513807019048828929> Ready!');
setInterval(() => {
for (const g of client.guilds.cache.values()) {
g.members.cache.clear();
g.presences.cache.clear();
}
}, 1000 * 60);
});
client.login(token);