Discord bot crashes when I attempt to include additional commands

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;
            }
        }
    }
});

dude your switch statements are messed up - you got nested switches which is causing the syntax errors. remove the second switch and just add the status case inside the first one with proper break statements. also that discord.io library is pretty outdated, might wanna consider switching to discord.js eventually

The issue is with your switch statement structure. You have two separate switch blocks when you should have one with multiple cases. The first switch case for ‘hello’ is missing a break statement, and then you’re starting another switch block which creates invalid syntax.

Here’s the corrected message handler:

switch(command) {
    case 'hello':
        client.sendMessage({
            to: channelID,
            message: 'Hi there!'
        });
        break;
    case 'status':
        client.sendMessage({
            to: channelID,
            message: 'Running fine!'
        });
        break;
}

I ran into similar problems when I started bot development. Missing break statements can cause commands to fall through to other cases, and improper switch syntax will prevent the script from running entirely.

Looking at your code, the problem stems from attempting to create nested switch statements which breaks JavaScript syntax rules. You cannot have a switch statement inside another switch case without proper closure. The first switch opens with the ‘hello’ case but never closes before you start the second switch for ‘status’. This creates a parsing error that prevents your bot from executing. Additionally, your first case lacks a break statement which would cause command execution to fall through even if the syntax was correct. I encountered this exact issue when expanding my first bot beyond a single command. The solution is consolidating both cases into a single switch block with proper break statements after each case. This approach scales much better when you need to add more commands later.