Xattics
Xattics

Reputation: 187

Making commands case insensitive [Discord bot] in JS

I've seen a lot of people asking the same thing on Stack Overflow but I didn't see any of the cases in which people use the same type of code as me, like for instance I cannot use .toLowerCase().

    if (message.substring(0, 1) == '+') {
    var args = message.substring(1).split(' ');
    var cmd = args[0];


    args = args.splice(1);
    switch(cmd) {
        // Help command
        case 'HELP':
            bot.sendMessage({
                to: channelID,
                message: commandList
            });
        break;

Upvotes: 0

Views: 119

Answers (1)

pacukluka
pacukluka

Reputation: 735

Try putting toUpperCase() here

var cmd = args[0].toUpperCase();

or here:

switch(cmd.toUpperCase()) {

And if youre getting an error saying toUpperCase cant be put on undefined, then your code is broken somewhere here:

var args = message.substring(1).split(' ');
var cmd = args[0];

so try and see if your message is actually what you think it is.

Upvotes: 3

Related Questions