I’m working on creating a simple Discord bot with basic functionality. I found a tutorial online, but it didn’t explain clearly how to implement multiple commands. When I tried duplicating some code sections to add more features, the bot completely stopped working.
I’ve been troubleshooting this for hours but can’t figure out what’s wrong. Every time I execute the script, it throws various syntax errors. Here’s my current code:
const Discord = require('discord.io');
const winston = require('winston');
const config = require('./config.json');
// Setup logger configuration
winston.remove(winston.transports.Console);
winston.add(new winston.transports.Console, {
colorize: true
});
winston.level = 'debug';
// Create Discord Bot instance
const client = new Discord.Client({
token: config.token,
autorun: true
});
client.on('ready', function (event) {
winston.info('Bot connected successfully');
winston.info('Logged in as: ');
winston.info(client.username + ' - (' + client.id + ')');
});
client.on('message', function (user, userID, channelID, message, event) {
if (message.substring(0, 1) == '!') {
var arguments = message.substring(1).split(' ');
var command = arguments[0];
arguments = arguments.splice(1);
switch(command) {
case 'hello':
client.sendMessage({
to: channelID,
message: 'Hi there!'
});
switch(command) {
case 'status':
client.sendMessage({
to: channelID,
message: 'Running fine!'
});
break;
}
}
}
});