【问题标题】:How to make items in a Discord bot currency system usable?如何使 Discord 机器人货币系统中的物品可用?
【发布时间】:2021-04-25 11:58:41
【问题描述】:

我最近一直在尝试使用 Sequelize 在 Discord 机器人货币系统中编写代码,但我编写的用于使项目可用于服务器的代码似乎不起作用。 我主要想要它,以便如果我输入 d!use 服务器成员可以使用该项目。 这是我写的一些代码:

UserItems.belongsTo(CurrencyShop, { foreignKey: 'item_id', as: 'item' });
const userItem = await UserItems.findOne({
where: { user_id: this.user_id, item_id: item.id },
});
if (!userItem) {
    return message.channel.send("You don't own this item!");
} else {
    return message.channel.send(`You used ${item}`);
    await user.removeItem(item);
}

提前非常感谢!

【问题讨论】:

    标签: discord.js bots currency items


    【解决方案1】:

    如果removeItem() 方法输入正确,这里唯一的问题是您在使用removeItem() 方法之前返回message.channel.send,这会导致在从数据库中删除项目之前生成if-else 语句。

    尝试将 if-else 语句更改为:

    if (!userItem) {
        return message.channel.send("You don't own this item!");
    } else {
        message.channel.send(`You used ${item}`);
        return await user.removeItem(item);
    }
    

    【讨论】:

      猜你喜欢
      • 2019-01-11
      • 1970-01-01
      • 2021-09-10
      • 2021-02-24
      • 2020-12-24
      • 1970-01-01
      • 2023-01-17
      • 2021-05-11
      • 2020-02-14
      相关资源
      最近更新 更多