如何从discord.py中的预定义矩阵中选择一个数字?

2024-10-06 06:49:09 发布

您现在位置:Python中文网/ 问答频道 /正文

我一直在尝试为客户编写一个机器人程序,但由于我自学成才,有时最简单的方面我就不知道了。我知道我以前知道如何执行此操作,但我需要修复以下代码:

@client.command()
async def rroulette(ctx):
  await ctx.send(f"Aye, {ctx.author.mention}! Choose a number beween **1** and **6**! We all know what happens if your number is chosen, though, Comrade! ;)")
  rroulette1 = await client.wait_for("Message")
  await ctx.send("Alright, Comrade! Here goes nothing!")
  await asyncio.sleep(2)
  rroulette2 = (random.randint(1, 6))
  if rroulette2 == rroulette1.content:
    await ctx.send("Oops! The number was " + rroulette1.content + "! You know what that means!")
else:
  await ctx.send("Ah, you are safe, Comrade! The number was not yours.")

bot总是使用else函数响应,即您的号码从未被选中。我不知道如何解决这个问题

正如您可能猜到的,代码的总体目的是玩俄罗斯轮盘赌。如果选择了您的号码,您将被静音5分钟。任何帮助都将不胜感激


Tags: the代码clientsendnumberifcontentawait
1条回答
网友
1楼 · 发布于 2024-10-06 06:49:09
rroulette2 = (random.randint(1, 6))
if rroulette2 == int(rroulette1.content):
  await ctx.send("Oops! The number was " + rroulette1.content + "! You know what that means!")
else:
  await ctx.send("Ah, you are safe, Comrade! The number was not yours.")

正如@Oli所说,rroulette1的内容始终是一个字符串,您需要将其转换为int,这应该可以工作

相关问题 更多 >