-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
57 lines (47 loc) · 1.95 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
require('dotenv').config();
const fs = require('fs');
const {Client, Collection, GatewayIntentBits, ActivityType} = require('discord.js');
const client = new Client({intents:[GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent, GatewayIntentBits.GuildVoiceStates]});
client.commands = new Collection();
client.aliases = new Collection();
var queue = {
connection: null,
songs: []
};
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
const api = require('./api.js');
for(const file of commandFiles) {
const command = require(`./commands/${file}`);
client.commands.set(command.name, command);
if(command.alias != undefined) client.aliases.set(command.alias, command);
}
client.on("ready", async () => {
console.log('Client user logged in: ' + client.user.tag);
client.user.setPresence({ activities: [{ type: ActivityType.Streaming, name: process.env.activity }] });
client.user.setStatus('idle');
});
client.on('messageCreate', message => {
if(!message.content.startsWith('m!') || message.author.bot) return;
const args = message.content.trim().slice(2).split(' ');
const commandName = args.shift().toLowerCase();
var command;
if(client.commands.get(commandName)) command = client.commands.get(commandName);
if(client.aliases.get(commandName)) command = client.aliases.get(commandName);
if(command == null) return;
if(process.env.debounce_activation_threshold != '0') {
let debounceStruct = api.checkDebounce(message.author.id);
if(debounceStruct.shouldRateLimit) {
return api.errorEmbed(`You're on command cooldown, chill out. \`${process.env.debounce_minimal_timeout - (debounceStruct.diff)}\` seconds remaining.`, api.prepareEmbedMessage(client), message);
}
}
try {
command.execute(message, args, client, queue);
} catch (error) {
console.error(error);
message.reply(error);
};
});
client.on('error', error => {
console.error(error);
});
client.login(process.env.token);