【问题标题】:Inventory command in currency system. (Discordpy)货币系统中的库存命令。 (不和谐)
【发布时间】:2022-01-18 14:53:25
【问题描述】:

好的,我为我的货币系统创建了一个库存命令,但我坚持使用它。如果用户的 inv 中没有任何内容,我应该如何准确定义?

我的代码:

bag = users[str(user.id)]["bag"] # This is just the json where the items are stored.
for item in bag:
            name = item["item"]
            amount = item["amount"]

            if name in bag == None:
                em.add_field(name="Your bag is empty.")
            else:
                em.add_field(name=name,value=amount)

        await ctx.send(embed=em)

追溯: 控制台中没有错误,它根本不起作用。

【问题讨论】:

  • 你的意思是if (name := item.get('item')) is None?
  • 空的bag 不意味着库存中没有任何东西吗? bag是什么类型的?
  • bag 是存储项目的 json。 bag = users[str(user.id)]["bag"]
  • @timgeb 是的,但这与我的代码相同,没有错误只是根本不起作用。
  • JSON 是一种数据交换格式,而不是一种类型。 bag 是什么类型? dict? set? list?还有什么? Sample code 应该是完整的。

标签: python discord.py


【解决方案1】:

我找到了解决办法。

解决办法:

if not name in bag:

解释:“name in bag”返回一个布尔值,它永远不会是“None”。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-11-10
    • 1970-01-01
    • 2021-07-04
    • 2021-06-09
    • 2021-12-28
    • 2020-07-13
    • 2020-09-26
    相关资源
    最近更新 更多