我希望我的机器人识别用户得到了正确或错误的答案,但是无论如何,该机器人都会返回错误的答案消息。这是我的代码:
@bot.command()
async def trivia(ctx):
trivfile = open("questions.txt")
allines = trivfile.readlines()
for i in allines:
qlist.append(i)
qnum = random.randint(1,len(qlist)-1)
del qlist[:]
line = (allines[qnum-1])
words = line.split()
embed = discord.Embed(
title = "Are you ready?",
description = f"``{questions[qnum-1]}``\n **:regional_indicator_a:{words[0]}\n :regional_indicator_b:{words[1]}\n :regional_indicator_c:{words[2]}\n :regional_indicator_d:{words[3]}\n**",
color = discord.Colour.red()
)
embed.set_thumbnail(url="https://www.budgetbytes.com/wp-content/uploads/2013/07/Creamy-Tomato-and-Spinach-Pasta-skillet-1-500x480.jpg")
await ctx.send(embed=embed)
def check(m):
return m.content == 'a' or 'A' or 'b' or 'B' or 'c' or 'C' or 'd' or 'D'
answer = await bot.wait_for('message',check=check)
if answer == words[4] or answer == words[5]:
await ctx.send(f"Congrats, {ctx.author.name}! That was the correct answer gg man")
else:
await ctx.send(f"Wrong, the correct answer was {words[5]}. smh big noob")
这是我的.txt文件,其中包含答案:
Achgabat Kabul Islamabad Bruhcity a A
1936 1914 1918 1890 b B
Jackson Astley Stalin Mercury b B
谢谢。
答案 0 :(得分:0)
Bot.wait_for
返回的参数反映传递给相关事件处理程序的参数。
在这种情况下,由于您正在等待消息事件,因此它将返回分配给answer
的{{3}}对象。您需要使用Message
属性进行比较。