首页 > 解决方案 > 尝试制作一条鱼命令 /discord.js

问题描述

现在,我已经有了我的商店和所有的物品。我想要用户,所以当他们购买 FishingRod 时,他们会被放入 anew Set();中,一旦他们进入该组,他们就可以使用该fish命令。这是我的“购买”命令代码:

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”时,它会将它们放入 Set 中。问题是当这种情况发生时,我尝试运行fish命令,它仍然说我没有钓鱼竿,需要买一个。任何帮助,将不胜感激。

标签: javascriptnode.jsbotsdiscord.js

解决方案


好的,您正在尝试将命令参数(它是一个数组)与字符串进行比较。你可以做得到args[0]第一个论点。此外,您正在制作它,以便它必须是“FishingRod”并且不能是小写。试试args[0].toLowerCase() === "fishingrod"


推荐阅读