Initial commit
This commit is contained in:
63
dist/index.js
vendored
Normal file
63
dist/index.js
vendored
Normal file
@@ -0,0 +1,63 @@
|
||||
import { Client, Collection, Events, GatewayIntentBits, PresenceUpdateStatus } from 'discord.js';
|
||||
import { env, requireEnv } from './config/env.js';
|
||||
import { migrate } from './db/migrate.js';
|
||||
import { registerMessageCreate } from './events/messageCreate.js';
|
||||
import { registerModerationLogs } from './events/guildBanKickLog.js';
|
||||
import * as setup from './commands/setup.js';
|
||||
import * as leaderboard from './commands/leaderboard.js';
|
||||
import * as profile from './commands/profile.js';
|
||||
import * as resetmemory from './commands/resetmemory.js';
|
||||
import { banExecute, kickExecute, timeoutExecute } from './commands/moderation.js';
|
||||
import { startQotdScheduler } from './scheduler/qotd.js';
|
||||
requireEnv('discordToken');
|
||||
const client = new Client({
|
||||
intents: [
|
||||
GatewayIntentBits.Guilds,
|
||||
GatewayIntentBits.GuildMembers,
|
||||
GatewayIntentBits.GuildMessages,
|
||||
GatewayIntentBits.MessageContent
|
||||
]
|
||||
});
|
||||
const commands = new Collection();
|
||||
commands.set('setup', setup.execute);
|
||||
commands.set('leaderboard', leaderboard.execute);
|
||||
commands.set('profile', profile.execute);
|
||||
commands.set('resetmemory', resetmemory.execute);
|
||||
commands.set('ban', banExecute);
|
||||
commands.set('kick', kickExecute);
|
||||
commands.set('timeout', timeoutExecute);
|
||||
client.once(Events.ClientReady, async (c) => {
|
||||
await migrate();
|
||||
registerMessageCreate(client);
|
||||
registerModerationLogs(client);
|
||||
startQotdScheduler(client);
|
||||
const setPresence = () => {
|
||||
const count = c.guilds.cache.size;
|
||||
c.user.setPresence({
|
||||
status: PresenceUpdateStatus.Online,
|
||||
activities: [{ name: `${count} servers`, type: 3 }]
|
||||
});
|
||||
};
|
||||
setPresence();
|
||||
setInterval(setPresence, 60_000);
|
||||
console.log(`Logged in as ${c.user.tag}`);
|
||||
});
|
||||
client.on(Events.InteractionCreate, async (interaction) => {
|
||||
if (!interaction.isChatInputCommand())
|
||||
return;
|
||||
const fn = commands.get(interaction.commandName);
|
||||
if (!fn)
|
||||
return;
|
||||
try {
|
||||
await fn(interaction);
|
||||
}
|
||||
catch (e) {
|
||||
const msg = 'Error while executing command.';
|
||||
if (interaction.deferred || interaction.replied)
|
||||
await interaction.followUp({ content: msg, ephemeral: true }).catch(() => null);
|
||||
else
|
||||
await interaction.reply({ content: msg, ephemeral: true }).catch(() => null);
|
||||
console.error(e);
|
||||
}
|
||||
});
|
||||
client.login(env.discordToken);
|
||||
Reference in New Issue
Block a user