This repository has been archived by the owner on Jan 25, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathindex.js
112 lines (96 loc) · 2.79 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
const Discord = require('discord.js');
const config = require('./config.js');
const client = new Discord.Client({
intents: [
'DirectMessageTyping',
'DirectMessages',
'GuildBans',
'GuildEmojisAndStickers',
'GuildMembers',
'GuildMessageTyping',
'GuildMessages',
'GuildPresences',
'Guilds',
'MessageContent',
],
});
const fs = require('fs');
const api = require('./libs/axios.js');
const logger = require('./utils/logger.js');
const userData = require('./utils/userData.js');
// Handle uncaught exceptions
process.on('uncaughtException', function (error) {
console.log(error.stack);
});
client.on('debug', (log) => {
logger(log);
});
// Access to client
client.login(config.botToken);
// Initialize bot
client.on('ready', async () => {
console.log(`BOT: Logged in as ${client.user.username}`);
// Set status
client.user.setStatus('online');
client.user.setActivity('LEADEROS');
// Initialize User Data
userData.init();
// Load Settings
client.settings = await api.getSettings();
// Get guild
client.guild = client.guilds.cache.get(client.settings.guildID);
if (!client.guild || client.guild === undefined) {
console.log('BOT: Guild not found.');
}
// Load Modules
const modules = [
{
name: 'roleSyncing',
status: client.settings.roleSyncingStatus,
},
{
name: 'support',
status: client.settings.ticketStatus,
},
];
console.log(`BOT: Loading ${modules.length} modules.`);
let moduleCount = 0;
modules.map((module) => {
if (!module.status) return;
moduleCount++;
require(`./modules/${module.name}.js`)(client);
});
console.log(`BOT: ${moduleCount} modules loaded.`);
// Load Commands
const commands = [];
client.commands = new Discord.Collection();
const commandFiles = fs
.readdirSync(`${__dirname}/commands`)
.filter((file) => file.endsWith('.js'));
console.log(`BOT: Loading ${commandFiles.length} commands.`);
commandFiles.map((file) => {
const cmd = require(`./commands/${file}`);
client.commands.set(cmd.data.name, cmd);
commands.push(cmd.data);
});
const rest = new Discord.REST({ version: '9' }).setToken(config.botToken);
rest
.put(Discord.Routes.applicationCommands(client.user.id), { body: commands })
.then(() => {
console.log(`BOT: ${commandFiles.length} commands loaded.`);
});
});
// Command Handler
client.on('interactionCreate', async (interaction) => {
if (
!interaction.isCommand() ||
!interaction.channel ||
interaction.channel.type === 'DM'
)
return;
const command = interaction.commandName;
const cmd = client.commands.get(command);
if (cmd) {
cmd.run(client, interaction);
}
});