-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
59 lines (45 loc) · 1.96 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
const fs = require('node:fs');
const path = require('node:path');
const { Client, GatewayIntentBits, Collection } = require('discord.js');
const { AutoPoster } = require('topgg-autoposter');
const { token, topggToken, webhookAuth } = require('./config.json');
const { Webhook } = require('@top-gg/sdk');
const app = require('express')();
const client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages] });
client.commands = new Collection();
client.collectCooldown = new Collection();
client.dailyCooldown = new Collection();
client.voteCooldown = new Collection();
if (topggToken !== 'TEST' && webhookAuth !== 'TEST') {
const ap = AutoPoster(topggToken, client);
ap.on('posted', (stats) => {
console.log(`Successfully posted bot stats to Top.gg, UrbanBot is on ${stats.serverCount} servers.`);
});
const dblWebhook = new Webhook(webhookAuth);
app.post('/dblwebhook', dblWebhook.listener(vote => {
console.log(`User voted on Top.gg! (id: ${vote.user})`);
client.voteCooldown.set(vote.user, true);
}));
app.listen(8087, () => {
console.log('Top.gg vote webhook is listening on port 8087!');
});
}
const eventsPath = path.join(__dirname, 'events');
const eventFiles = fs.readdirSync(eventsPath).filter(file => file.endsWith('.js'));
for (const file of eventFiles) {
const filePath = path.join(eventsPath, file);
const event = require(filePath);
if (event.once) {
client.once(event.name, (...args) => event.execute(client, ...args));
} else {
client.on(event.name, (...args) => event.execute(client, ...args));
}
}
const commandsPath = path.join(__dirname, 'commands');
const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const filePath = path.join(commandsPath, file);
const command = require(filePath);
client.commands.set(command.data.name, command);
}
client.login(token);