-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
94 lines (80 loc) · 4.04 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
const fs = require('fs-extra');
const path = require('node:path');
const { Client, Collection, GatewayIntentBits } = require('discord.js');
const { token } = require('./config/token.json');
const { QuickDB } = require('quick.db');
const jsonc = require('jsonc');
const db = new QuickDB();
process.on('unhandledRejection', (reason, promise, a) => {
console.log(reason, promise, a)
})
process.stdout.write(`
\x1b[38;2;143;110;250m████████╗██╗ ██████╗██╗ ██╗███████╗████████╗ ██████╗ ██████╗ ████████╗
\x1b[38;2;157;101;254m╚══██╔══╝██║██╔════╝██║ ██╔╝██╔════╝╚══██╔══╝ ██╔══██╗██╔═══██╗╚══██╔══╝
\x1b[38;2;172;90;255m ██║ ██║██║ █████╔╝ █████╗ ██║ ██████╔╝██║ ██║ ██║
\x1b[38;2;188;76;255m ██║ ██║██║ ██╔═██╗ ██╔══╝ ██║ ██╔══██╗██║ ██║ ██║
\x1b[38;2;205;54;255m ██║ ██║╚██████╗██║ ██╗███████╗ ██║ ██████╔╝╚██████╔╝ ██║
\x1b[38;2;222;0;255m ╚═╝ ╚═╝ ╚═════╝╚═╝ ╚═╝╚══════╝ ╚═╝ ╚═════╝ ╚═════╝ ╚═╝\x1b[0m
https://github.com/Sayrix/ticket-bot
Connecting to Discord...`)
const client = new Client({ intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent
] });
// All variables stored in the client object
client.db = db;
client.discord = require('discord.js');
client.config = jsonc.parse(fs.readFileSync(path.join(__dirname, 'config/config.jsonc'), 'utf8'));
client.locales = require(`./locales/${client.config.lang}.json`);
client.embeds = client.locales.embeds;
client.log = require("./utils/logs.js").log;
client.msToHm = function dhm (ms) {
const days = Math.floor(ms / (24*60*60*1000));
const daysms = ms % (24*60*60*1000);
const hours = Math.floor(daysms / (60*60*1000));
const hoursms = ms % (60*60*1000);
const minutes = Math.floor(hoursms / (60*1000));
const minutesms = ms % (60*1000);
const sec = Math.floor(minutesms / 1000);
if (days > 0) return `${days}d ${hours}h ${minutes}m ${sec}s`;
if (hours > 0) return `${hours}h ${minutes}m ${sec}s`;
if (minutes > 0) return `${minutes}m ${sec}s`;
if (sec > 0) return `${sec}s`;
return "0s";
}
// Command handler
client.commands = new Collection();
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);
}
// Execute commands
client.on('interactionCreate', async interaction => {
if (!interaction.isChatInputCommand()) return;
const command = client.commands.get(interaction.commandName);
if (!command) return;
try {
await command.execute(interaction, client);
} catch (error) {
console.error(error);
await interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true });
}
});
// Event handler
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(...args));
} else {
client.on(event.name, (...args) => event.execute(...args, client));
}
}
// Login the bot
client.login(token);