Discordjs v12 参数

Discordjs v12 args

谁能帮我解决参数问题?我已经测试了 .bet (number under 99) 但它不会回复我的消息并且与 .bet (number more than 100)

相同
//My code
if (message.content.startsWith(".bet")) {
let bet = args.join(" ");
 // let bet = args[1]
  if (!args[0]) {
        return message.channel.send(`Woops, looks like you forgot to specify an amount to bet`)
    }

这就是问题所在

//the problems

if (args[1] <= 99) {
  return
  message.channel.send("Sorry, You cannot bet under 99$")
  
}
if (args[2] >= 100) {
  return
  await db.add(`user.money_${message.author.id}`, -bet)

  message.channel.send("test")
}  

//
}

您在 post 中添加的代码片段没有显示您定义 args 变量的部分,所以我在这里创建了一个。

const args = message.content.slice(".".length).trim().split(/ +/g).shift(); // split the message content on space and return the arguments

if (message.content.startsWith(".bet")) {
    if (!args[0]) { // if there's no argument
        return message.reply("Woops, looks like you forgot to specify an amount to bet!");
    }

    if (args[0] <= 99) { // if bet is equal/less than 99
        return message.reply("Sorry, you cannot bet under .");
    }

    if (args[0] >= 100) { // if bet is equal/greater than 100
        await db.add(`user.money_${message.author.id}`, -args[0]);
        return message.reply("Successfully added a bet.");
    }
}