59 lines
1.8 KiB
TypeScript
59 lines
1.8 KiB
TypeScript
import * as Discord from 'discord.js';
|
|
import * as fs from 'fs';
|
|
const { token, disableDaytimeAnnouncements } = JSON.parse(fs.readFileSync('./config.json', 'utf8'));
|
|
import * as path from 'path';
|
|
import { initializeCounter } from './lib/counter';
|
|
import { getNextAnnouncementTime, initializeAnnouncements, loadNext, loadSubscriptions, next, saveNext, subscriptions, timeAnnouncements } from './lib/subscriptions';
|
|
|
|
loadNext();
|
|
loadSubscriptions();
|
|
|
|
const bot = new Discord.Client({
|
|
intents: [
|
|
Discord.Intents.FLAGS.GUILDS,
|
|
Discord.Intents.FLAGS.GUILD_MESSAGES,
|
|
Discord.Intents.FLAGS.GUILD_VOICE_STATES,
|
|
Discord.Intents.FLAGS.GUILD_MESSAGE_REACTIONS,
|
|
Discord.Intents.FLAGS.GUILD_MEMBERS,
|
|
],
|
|
});
|
|
|
|
bot.on('ready', async () => {
|
|
initializeCounter();
|
|
|
|
if (!disableDaytimeAnnouncements) {
|
|
initializeAnnouncements(bot);
|
|
}
|
|
|
|
bot.commands = new Discord.Collection();
|
|
const cmdFiles = fs.readdirSync(path.join(__dirname, './commands')).filter((file) => file.endsWith('.js'));
|
|
for (const file of cmdFiles) {
|
|
const cmd = (await import(`./commands/${file}`));
|
|
bot.commands.set(cmd.data.name, cmd);
|
|
if (cmd.onClientReady) cmd.onClientReady(bot);
|
|
}
|
|
|
|
console.log('jillo online');
|
|
});
|
|
|
|
bot.on('interactionCreate', async (interaction) => {
|
|
if (!interaction.isCommand()) return;
|
|
|
|
const command = interaction.client.commands.get(interaction.commandName);
|
|
if (!command) return;
|
|
|
|
try {
|
|
await command.execute(interaction, interaction.member);
|
|
} catch (error) {
|
|
interaction.reply({ content: '`ERROR`', ephemeral: true });
|
|
console.error(error);
|
|
}
|
|
});
|
|
|
|
bot.on('messageDelete', (msg) => {
|
|
console.log(`${msg.author?.username}#${msg.author?.discriminator} in #${msg.channel instanceof Discord.TextChannel ? msg.channel.name : '?'} at ${msg.createdAt.toISOString()}`);
|
|
console.log(`${msg.content}`);
|
|
});
|
|
|
|
bot.login(token);
|