58 lines
1.5 KiB
TypeScript
58 lines
1.5 KiB
TypeScript
import {Events, GatewayIntentBits, ActivityType} from 'discord.js';
|
|
|
|
// Global config
|
|
import {config} from './config';
|
|
|
|
// Classes
|
|
import {ExtendedClient} from './classes/extendedclient';
|
|
|
|
// Initialization functions
|
|
import {setNickname} from './init/set-nickname';
|
|
import {loadCommands} from './init/load-commands';
|
|
import {registerCommands} from './init/register-commands';
|
|
import {sendReadyDM} from './init/ready-dm';
|
|
|
|
// Event-handling functions
|
|
import {handleCommands} from './events/commands';
|
|
|
|
// Sub-services
|
|
import {logger} from './logger';
|
|
import {runMongo} from './mongo';
|
|
|
|
logger.info(config.adminId);
|
|
|
|
const client = new ExtendedClient({ intents: [GatewayIntentBits.Guilds] });
|
|
client.login(config.token);
|
|
|
|
client.on(Events.InteractionCreate, handleCommands);
|
|
|
|
client.once(Events.ClientReady, async c => {
|
|
logger.info(`Logged in as ${c.user.tag}`);
|
|
|
|
if(client.user){
|
|
client.user.setPresence({
|
|
activities: [{
|
|
name: 'ぼくたちは勉強ができない',
|
|
type: ActivityType.Watching,
|
|
}],
|
|
status: 'online',
|
|
});
|
|
logger.info('Set status');
|
|
}
|
|
|
|
await setNickname(client);
|
|
logger.info(`Set nickname as ${config.nickname}`);
|
|
|
|
const commands = await loadCommands(client);
|
|
logger.info(`${commands.length} commands loaded.`);
|
|
|
|
const regCmdCnt = await registerCommands(commands);
|
|
logger.info(`${regCmdCnt} commands registered.`);
|
|
|
|
await runMongo();
|
|
logger.info(`Database ready`);
|
|
|
|
logger.info(`Ready!`);
|
|
await sendReadyDM(client, config.adminId);
|
|
});
|