jillo-bot/src/index.ts

63 lines
2.0 KiB
TypeScript
Raw Normal View History

import { Client, GatewayIntentBits, Events, Collection, TextChannel } from 'discord.js';
2022-06-08 02:57:15 +02:00
import * as fs from 'fs';
const { token } = JSON.parse(fs.readFileSync('./config.json', 'utf8'));
2022-06-08 02:57:15 +02:00
import * as path from 'path';
2022-07-19 21:39:34 +02:00
import { initializeCounter } from './lib/counter';
import { initializeAnnouncements } from './lib/subscriptions';
import { initTables } from './lib/db';
2022-06-08 01:28:20 +02:00
const bot = new Client({
2022-06-08 03:46:00 +02:00
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.GuildVoiceStates,
GatewayIntentBits.GuildMessageReactions,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.MessageContent,
GatewayIntentBits.DirectMessages
2022-06-08 03:46:00 +02:00
],
2022-06-08 01:28:20 +02:00
});
bot.on(Events.ClientReady, async () => {
2023-04-19 21:08:26 +02:00
initializeCounter(false);
initializeCounter(true);
2022-07-19 21:39:34 +02:00
initializeAnnouncements(bot);
2022-06-08 03:46:00 +02:00
bot.commands = new Collection();
2022-06-08 03:46:00 +02:00
const cmdFiles = fs.readdirSync(path.join(__dirname, './commands')).filter((file) => file.endsWith('.js'));
2022-06-08 01:28:20 +02:00
for (const file of cmdFiles) {
2022-06-08 02:57:15 +02:00
const cmd = (await import(`./commands/${file}`));
2022-06-08 01:28:20 +02:00
bot.commands.set(cmd.data.name, cmd);
2022-06-08 03:46:00 +02:00
if (cmd.onClientReady) cmd.onClientReady(bot);
2022-06-08 01:28:20 +02:00
}
2022-07-19 20:48:02 +02:00
console.log('jillo online');
2022-06-08 01:28:20 +02:00
});
bot.on(Events.InteractionCreate, async (interaction) => {
2022-06-08 03:46:00 +02:00
if (!interaction.isCommand()) return;
2022-06-08 01:28:20 +02:00
2022-06-08 03:46:00 +02:00
const command = interaction.client.commands.get(interaction.commandName);
if (!command) return;
2022-06-08 01:28:20 +02:00
2022-06-08 03:46:00 +02:00
try {
await command.execute(interaction, interaction.member);
} catch (error) {
2023-10-29 10:22:23 +01:00
if (interaction.isRepliable() && !interaction.replied && !interaction.deferred) interaction.reply({ content: '`ERROR`', ephemeral: true });
if (interaction.deferred) interaction.followUp('`ERROR`');
2022-06-08 03:46:00 +02:00
console.error(error);
}
2022-06-08 01:28:20 +02:00
});
bot.on(Events.MessageDelete, (msg) => {
console.log(`${msg.author?.username}#${msg.author?.discriminator} in #${msg.channel instanceof TextChannel ? msg.channel.name : '?'} at ${msg.createdAt.toISOString()}`);
2023-01-20 22:00:16 +01:00
console.log(`${msg.content}`);
});
2023-10-29 11:22:21 +01:00
process.on('uncaughtException', err => {
console.error(err);
});
initTables().then(() => bot.login(token));