-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
96 lines (82 loc) · 2.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
const fs = require('fs');
const { Client, Collection, Intents } = require('discord.js');
const { adminId, guildId, token } = require('./config.json');
const { customIds } = require('./globals');
const client = new Client({ intents: [Intents.FLAGS.GUILDS] });
// Add slash commands
client.commands = new Collection();
const 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);
}
client.once('ready', () => {
console.log('Ready!');
client.user.setActivity('#RotMWin');
setupPerms();
});
// Event listener for slash command interaction
client.on('interactionCreate', async interaction => {
if (!interaction.isCommand()) return;
const command = client.commands.get(interaction.commandName);
if (!command) return;
try {
await command.execute(interaction);
}
catch (error) {
console.error(error);
return interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true });
}
});
// Event listener for button interaction
client.on('interactionCreate', interaction => {
if (!interaction.isButton()) return;
let command;
switch (interaction.customId) {
case customIds.PAYOUT:
command = client.commands.get('payout');
command.payout(interaction);
break;
case customIds.RESET:
command = client.commands.get('reset');
command.reset(interaction);
break;
}
});
client.login(token);
// Adds default permissions to commands
async function setupPerms() {
const adminRole = [{
id: adminId,
type: 'ROLE',
permission: true,
}];
const fullPermissions = [
{
// cancel
id: '938973913864626238',
permissions: adminRole,
},
{
// close
id: '938973913864626239',
permissions: adminRole,
},
{
// open
id: '938973913864626241',
permissions: adminRole,
},
{
// reset
id: '938973913864626245',
permissions: adminRole,
},
{
// payout
id: '938973913864626243',
permissions: adminRole,
},
];
await client.guilds.cache.get(guildId)?.commands.permissions.set({ fullPermissions });
}