Bean
Bean

Reputation: 11

Discord bot not responding to command

I'm trying to code the bot to generate a random percentage when the command !percent is used while also mentioning the user. When I use the command it doesn't seem to work but no errors pop up in the console.

if (message.content == ("!Percent" || message.content == "!percent")) {
        if (message.isMemberMentioned()) { 
            message.isMemberMentioned.users.forEach((k, v) => { 
                message.channel.send( v + ' is ' + ( Math.floor(Math.random() * 100) + 1 ) + "%  ! " );
          })
        }
      }
})

Upvotes: 0

Views: 53

Answers (1)

Finbar
Finbar

Reputation: 1353

I think you want

if(message.content.toLowerCase() === '!percent'){...

or..

if(['!Percent', '!percent'].includes(message.content)){...

Not
if (message.content == ("!Percent" || message.content == "!percent")) {...

Is wrong as its comparing message content, a string, to a boolean as "!Percent" will always be true.

The Message class doesn't have a #isMemberMentioned method documented (never existed??) if you want support for that edit your post with the function code. Same goes for the isMemberMentioned property on the Message class variable.

Upvotes: 1

Related Questions