Как заставить бот Python Discord ждать определенного ответа на викторину? - PullRequest
0 голосов
/ 19 января 2020

Я хочу, чтобы мой бот распознал, получил ли пользователь правильный или неправильный ответ, но бот возвращает неправильный ответ, несмотря ни на что. Вот мой код:

@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

Спасибо.

1 Ответ

0 голосов
/ 19 января 2020

Bot.wait_for возвращает аргументы, которые отражают параметры, переданные соответствующему обработчику событий.
В этом случае, так как вы ожидаете событие сообщения, он вернет Message объект, который присвоен answer. Для сравнения вы захотите использовать атрибут Message.content.

...