【问题标题】:How should i define "max" or "all" at a deposit command. (discordpy)我应该如何在存款命令中定义“最大”或“全部”。 (不和谐)
【发布时间】:2022-01-19 20:29:17
【问题描述】:

好的,我为我的货币游戏制定了存款命令,但我坚持下去。我该怎么做?

if amount == "max" or "all":
            amount = users[str(user.id)]["wallet"]
            await self.update_bank(ctx.author,-amount,"wallet")
            await self.update_bank(ctx.author, +amount,"bank")

追溯:

Command raised an exception: ValueError: invalid literal for int() with base 10: 'max'

【问题讨论】:

  • if amount == "max" or "all" 不是测试两个值的正确方法。改用if amount == "max" or "amount == "all",或者更好的if amount in ["max", "all"]
  • 是 max 还是 all 应该是包含 int 的变量?
  • 答案很简单,你得到了 str 的价值。将其转换为 int

标签: python discord.py


【解决方案1】:

假设amount 的类型是int,您的if 语句是错误的。

应该是:

if str(amount) == "max" or str(amount) == "all":
....

【讨论】:

  • 如果amount是一个int,str怎么会等于“max”或“all”?
  • 如果你假设 amount 是 int 那么你在这里写的 if 语句永远不会被执行。
  • 你们俩都对,应该评论没有回答。
猜你喜欢
  • 2021-02-25
  • 2020-02-25
  • 2022-01-06
  • 2020-12-31
  • 2021-08-13
  • 2019-09-30
  • 2021-06-17
  • 1970-01-01
  • 2021-12-28
相关资源
最近更新 更多