【问题标题】:Elif and else problems - Discord botElif 和其他问题 - Discord 机器人
【发布时间】:2021-03-24 14:46:27
【问题描述】:

所以基本上我有一个不和谐的机器人,你必须从 {min} - {max} 中猜测一个数字才能赢得价格。管理员有权执行命令 -guess {min} {max}。 Discord 用户猜测频道中的数字,该命令已执行。除了 elif 和 else 函数之外,几乎所有东西都能完美运行。它们不会在控制台中显示任何错误,机器人只是忽略它们。如果他们猜对了这个数字,机器人会说({msg.author} 猜到了这个数字。这个数字是 {choice})。我想制作,如果他们猜到一个高于 {max} 的数字,它只会显示(数字太大,尝试在 {min} - {max} 之间)。有我的代码。你能告诉我为什么我的 elif 和 else 函数总是被忽略吗?

@bot.command()
async def guess(ctx, min:int, max:int):
    if not ctx.author.id in bot.devs:
        return
    choice = random.randint(min, max)
    print(choice)
    await ctx.send(f'Choose a number between {min} - {max}')

    def check(m):
        return m.content == f"{choice}" and m.channel == ctx.channel
    msg = await bot.wait_for("message", check=check)
    if msg.content == f"{choice}":
        embed=discord.Embed(title=f"**Giveaway Winner**", description=f"{msg.author} has won the giveaway! The answer was {choice}")
        await ctx.send(embed=embed)
    elif msg.content >= f"{max}":
        embed=discord.Embed(title=f"**Number is too big**", description=f"{msg.author} try between {min} - {max}")
        await ctx.send(embed=embed)
    else:
        await ctx.send(f"{msg.author}You guessed wrong. Try again")

【问题讨论】:

    标签: python discord bots discord.py


    【解决方案1】:

    elif msg.content >= f"{max}": 行中,您正在使用数学运算符比较两个字符串, 而是尝试elif int(msg.content) >= max:

    【讨论】:

    • elif int(msg.content) >= max:
    猜你喜欢
    • 2021-11-10
    • 2019-08-14
    • 2020-07-04
    • 2021-12-12
    • 2019-11-09
    • 2021-02-09
    • 2020-12-23
    • 2020-12-30
    • 2020-05-15
    相关资源
    最近更新 更多