javascript - 尝试制作一条鱼命令 /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
命令,它仍然说我没有钓鱼竿,需要买一个。任何帮助,将不胜感激。
解决方案
好的,您正在尝试将命令参数(它是一个数组)与字符串进行比较。你可以做得到args[0]
第一个论点。此外,您正在制作它,以便它必须是“FishingRod”并且不能是小写。试试args[0].toLowerCase() === "fishingrod"
。
推荐阅读
- cuda - Nvidia GPU 同时访问全局内存中的单个位置
- cybersource - Flex MicroForm 信用卡品牌标志
- c++ - 使用 is_same_v 自动推导类型
- linux - Mac OS Catalina zshell:cat -A 是非法的,那么替代品是什么?
- java - 是否可以从 Kotlin 评论链接 Java 方法?
- node.js - 如何在文本索引Mongodb中将精确短语与动态字符串匹配?
- typo3 - TYPO3 - TCA 迁移 - 信息还是待办事项?
- scala - Scala Apriori算法:如果第一个索引值相同,则从两个项目集列表生成三个项目集
- javascript - 在 NextJS SSR 流程中何时以及如何调用 React 生命周期方法?
- asp.net - LINQ to Entities 无法识别其中的方法调用