discord_bot/server.js
SileNce5k c51a4fa976
Pass objects on command.execute
Pass objects instead of using a switch statement.
Now I don't have to restart the bot whenever I add a new command
that needs specific arguments other than 'message'.
2021-03-09 18:50:27 +01:00

44 lines
No EOL
1 KiB
JavaScript

const fs = require('fs')
const Discord = require('discord.js');
const client = new Discord.Client({ disableEveryone: true });
const {
prefix,
token,
} = require('./config.json');
client.commands = new Discord.Collection();
var reloadCommands = require("./util/reloadCommands.js")
reloadCommands(client)
client.once('ready', () => {
console.log('Ready!');
client.user.setActivity(prefix, { type: 'LISTENING' });
});
client.once('reconnecting', () => {
console.log('Reconnecting!');
});
client.once('disconnect', () => {
console.log('Disconnect!');
});
client.on('message', async message => {
const args = message.content.slice(prefix.length).split(" ")
const commandName = args.shift().toLowerCase();
const command = client.commands.get(commandName);
if (!message.guild) return;
if (message.author.bot) return;
if (!message.content.startsWith(prefix)) return;
try {
command.execute({message:message, args:args, client: client})
} catch (error) {
console.log(`${error}\n-------`)
}
});
client.login(token);