【发布时间】: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