module.exports = function Events(bot) { let r; bot.on('ready', async () => { console.log(`Successfully connected as user ${bot.user.username}#${bot.user.discriminator}`); r = new RegExp(`^(?:<@!?${bot.user.id}> +|-)\\b`); bot.editStatus('online', { name: `LaTeX.`, type: 3, }); }); bot.on('error', (err, id) => { console.error(`Error encountered on shard ${id}`); console.error(err); }); bot.on('messageCreate', async (msg) => { if (!r) { console.error('Some real shit hapened : message matching regex hasn\'t been defined for some reason.'); process.exit(); } let content = msg.content.replace(r, ''); if (content === msg.content) return; if (msg.author.bot) return; if (msg.author === bot.user) return; if (msg.channel.type !== 0) return; console.log(`Command '${msg.content}' issued`); let trimmedContent = content.trim(); let result = bot.handler.apply(trimmedContent, msg); if (Array.isArray(result)) { bot.createMessage(msg.channel.id, `Missing permissions : ${result.join(', ')}`).catch(console.error); } }); };