-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
94 lines (80 loc) · 2.68 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
// Imports
const { Client, Intents, Collection } = require('discord.js');
const fs = require('fs');
const Limit = require('./Limiter.js');
const Queue = require('queue-promise');
const limiter = new Limit(49);
const { REST } = require('@discordjs/rest');
const { Routes } = require('discord-api-types/v9');
// Creates a rate limiting queue
const queue = new Queue({
concurrent: 1
});
// Prefix to call the bot
const prefix = 'src!';
// Determines the token for bot
let token = '';
if (fs.existsSync('./token.json')) {
const tokenFile = require('./token.json');
token = tokenFile.token;
} else {
token = process.env.token;
}
// Creates new Client
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] });
client.commands = new Collection();
const commands = [];
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const command = require(`./commands/${file}`);
commands.push(command.data.toJSON());
client.commands.set(command.data.name, command);
}
const rest = new REST({ version: '9' }).setToken(token);
/**
(async () => {
try {
console.log('Started refreshing application (/) commands.');
await rest.put(
Routes.applicationGuildCommands("728401850033897574", "430074563703996417"),
{ body: [] },
);
console.log('Successfully reloaded application (/) commands.');
} catch (error) {
console.error(error);
}
})();
*/
// Sets bot activity and announces that bot is ready for use
client.once('ready', async () => {
client.user.setActivity('speedrun.com | /help', { type: 'WATCHING' })
console.log('Ready!');
});
client.on('messageCreate', async message => {
// Checks if message starts with the given prefix
if (!message.content.toLowerCase().startsWith(prefix) || message.author.bot) return;
console.log(message.content);
//await message.reply("Please use the slash commands instead of the src! prefix.");
});
client.on('interactionCreate', async interaction => {
if(interaction.isCommand()) {
if (!client.commands.has(interaction.commandName)) return;
await interaction.deferReply();
try {
await client.commands.get(interaction.commandName).execute(interaction);
} catch (error) {
console.error(error);
await interaction.editReply({ content: 'There was an error while executing this command!', ephemeral: true });
}
} else if(interaction.isSelectMenu()) {
await client.commands.get('hypixel').execute(interaction);
}
});
client.login(token);
exports.tokens = token;
exports.limit = function getLimit() {
return limiter;
}
exports.queue = function getQueue() {
return queue;
}