Spot/bot.js
Celeste 6688d4dcd8 Update deps
Update to messages.json instead of messages.js
2022-10-21 12:51:50 +02:00

45 lines
1.3 KiB
JavaScript

const Logger = require('@lilywonhalf/pretty-logger');
const { Client } = require('discord.js');
const Config = require('./config.json');
const Command = require('./model/command');
const fs = require('fs');
const dotenv = require('dotenv')
dotenv.config();
global.bot = new Client({ fetchAllMembers: true });
global.isRightGuild = (guildSnowflake) => guildSnowflake === Config.guild;
const crashRecover = (exception) => {
Logger.exception(exception);
Logger.notice('Need reboot');
};
process.on('uncaughtException', crashRecover);
bot.on('error', crashRecover);
Command.init();
const help = require("./command/help");
bot.ws.on('INTERACTION_CREATE', help.interactionHandler);
bot.on('ready', () => {
fs.readdirSync('./event/')
.filter(filename => filename.endsWith('.js'))
.map(filename => filename.substr(0, filename.length - 3))
.forEach(filename => {
const event = filename.replace(/([_-][a-z])/gu, character => `${character.substr(1).toUpperCase()}`);
if (filename !== 'ready') {
bot.on(event, require(`./event/${filename}`));
} else {
require(`./event/${filename}`)();
}
});
});
Logger.info('--------');
Logger.info('Logging in...');
bot.login(process.env.token);