简体   繁体   中英

Command not executing

I want to check if "sender" has one of two roles required, but the command is not executing. No errors in console, just command doesn't execute.

const revAmount = commandArgs
  .split(/ +/g)
  .find((arg) => !/<@!?\d+>/g.test(arg));
const revTarget = message.mentions.users.first();
const sender = message.author;

if (
  sender === message.member.roles.cache.has('806432940094390273') ||
  sender === message.member.roles.cache.has('806433001843326996')
) {
  if (!revAmount || isNaN(revAmount))
    return message.channel.send(
      `Sorry ${message.author}, that's an invalid amount.`,
    );
  if (revAmount <= 0)
    return message.channel.send(
      `Please enter an amount greater than zero, ${message.author}.`,
    );

  currency.add(revTarget.id, -revAmount);
}

Does someone know what is wrong in here?

roles.cache is a collection and their has() method returns a boolean.

When you check if sender === message.member.roles.cache.has(...) , you're checking if an object is strictly equal to a boolean. It will always return false so anything inside that if statement is ignored.

You can remove sender === and just check if the member has the required role:

if (
  message.member.roles.cache.has('806432940094390273') ||
  message.member.roles.cache.has('806433001843326996')
) {

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM