【发布时间】:2018-12-11 14:30:04
【问题描述】:
基本上我正在做一个测验,我希望能够搜索答案并确定哪条消息只包含艺术家,哪条消息只包含歌曲名称,以及哪条消息同时显示它们。我已经制作了 3 个检查函数来显示这一点,但是我希望所有 3 个 wait_for_message 语句并排运行。关于如何解决这个问题的任何想法?
await client.say("What is the song name and artist?")
def check1(msg):
return name in msg.content.upper() and artist not in msg.content.upper()
def check2(msg):
return artist in msg.content.upper() and name not in msg.content.upper()
def check3(msg):
return name in msg.content.upper() and artist in msg.content.upper()
msg1 = await client.wait_for_message(timeout=10, check=check1)
msg2 = await client.wait_for_message(timeout=10, check=check2)
msg3 = await client.wait_for_message(timeout=20, check=check3)
if msg3 is not None:
await client.say("@{} got both of them right! It was indeed {} by {}".format(msg3.author, toString(name),
toString(artist)))
elif msg1 is not None and msg2 is not None:
await client.say("@{} got the song name and @{} got the artist name! It was indeed {} by {}".format(msg1.author,
msg2.author, toString(name), toString(artist)))
elif msg1 is not None and msg2 is None:
await client.say("@{} got the song name but no one got the artist! It was {} by {}".format(msg1.author,
toString(name), toString(artist)))
elif msg1 is None and msg2 is not None:
await client.say("@{} got the artist name but no one got the song name! It was {} by {}".format(msg2.author,
toString(name), toString(artist)))
elif msg1 is None and msg2 is None and msg3 is None:
await client.say("No one got it! It was {} by {}! Better luck next time".format(toString(name), toString(artist)))
【问题讨论】:
-
看看异步模块
-
相反,检查符合任何这些条件的邮件,然后将其分类到
wait_for_message之外 -
@PatrickHaugh 我认为他正在等待这三个人,这样如果人们只猜名字,其他人仍然可以尝试猜出艺术家或两者兼而有之。
标签: python discord discord.py