提问者:小点点

尝试创建一个fish命令/discord.js


现在,我已经有了我的商店和所有的商品。我希望用户在购买鱼竿时,会被放入一个new Set();中,一旦进入该集合,就可以使用fish命令。下面是“buy”命令的代码:

else if (command === 'buy') {
        const args = message.content.slice(PREFIX.length).trim().split(' ');

        if (isDead.has(message.author.id)) {
            message.channel.send('You\'re dead right now lmao you need to wait 5 more minutes before using any more currency and game related commands');
        }
        const item = await CurrencyShop.findOne({ where: { name: { [Op.like]: commandArgs } } });
        if (!item) return message.channel.send('That item doesn\'t exist.');
        if (args === 'FishingRod') {
            hasRod.add(message.author.id);
        }
        if (item.cost > currency.getBalance(message.author.id)) {
            return message.channel.send(`You don't have enough currency, ${message.author}`);
        }
        const user = await Users.findOne({ where: { user_id: message.author.id } });
        currency.add(message.author.id, -item.cost);
        await user.addItem(item);

        message.channel.send(`You've bought a ${item.name}`);
    }

正如你所看到的,我已经做了它,所以当args是'Fishingrod',它把他们放在设置。问题是,当发生这种情况时,当我尝试运行fish命令时,它仍然显示我没有鱼竿,需要买一根。如有任何帮助,我们将不胜感激。


共1个答案

匿名用户

好的,您正在尝试将命令参数(它是一个数组)与字符串进行比较。您只需执行args[0]即可获得第一个参数。另外,你要把它做成“鱼竿”,不能是小写的。尝试args[0].ToLowerCase()===“fishingrod”