renesansz / discord-greeter-bot

My greeter bot for Discord
MIT License
49 stars 38 forks source link

Multiple Responses Occur via Single Command #234

Closed cahallian closed 5 years ago

cahallian commented 5 years ago

I used the code and got the bot to work with a single case, but it seems like now that I've added additional cases, when sending a command, the response messages for multiple cases return.

For example, see the following cases:

bot.on('message', function (user, userID, channelID, message, evt) {
    if (message.substring(0, 1) == '!') {
        var args = message.substring(1).split(' ');
        var cmd = args[0];  

        args = args.splice(1);
        switch(cmd) {
            case 'turkey':
                bot.sendMessage({
                    to: channelID,
                    message: ':turkey: gobble gobble cockadoodle doo'
                });     
        case 'monny':
                bot.sendMessage({
                    to: channelID,
                    message: '@Monathan Jchendrix where you be'
                }); 

So what happens is when a !turkey command is sent, the bot will send multiple messages:

Botty_Boi_2: @Monathan Jchendrix where you be :turkey: gobble gobble cockadoodle doo

Any idea why a single command is calling multiple cases even when they don't apply?

GuNfRe4k commented 5 years ago

You need a break line

like so

   args = args.splice(1);
   switch(cmd) {
       case 'turkey':
           bot.sendMessage({
               to: channelID,
               message: ':turkey: gobble gobble cockadoodle doo'
           });      
      break
   case 'monny':
           bot.sendMessage({
               to: channelID,
               message: '@Monathan Jchendrix where you be'
           });
cahallian commented 5 years ago

That took care of it. Thanks!