我正在尝试执行子手游戏,但问题是客户只是将自己的消息当作消息。如何获得等待消息以仅接受某些用户的输入?
到目前为止,这是我的代码:
@client.command()
async def hangman():
guess = ""
hp = 6
word = "Banana"
slot = slotMaker(word, guess)
await client.say("Let`s play the hangman! \n The word is a fruit \n" + slot)
while slot != word and hp > 0:
guess += client.wait_for_message()
slot = slotMaker(word, guess)
await client.say(slot)
if letterChecker(word, guess):
pass
else:
hp -= 1
await client.say("Your hp is now " + str(hp) + ".")
编辑:以下是在不和谐频道中发送的消息:
Esdver9000Today at 11:58 PM
!hangman
sawg112BOTToday at 11:58 PM
Let`s play the hangman!
The word is a fruit
------
-anana
Your hp is now 5.
-anana
Your hp is now 4.
-anana
Your hp is now 3.
-anana
Your hp is now 2.
-anana
Your hp is now 1.
-anana
答案 0 :(得分:0)
Client.wait_for_message
有一个可选的author
参数,您可以使用该参数来接受来自调用命令的人的消息。您可能还应该提供一个channel
参数,以免使用用户在其他渠道中发送的消息。
msg = await client.wait_for_message(author=ctx.message.author, channel=ctx.message.channel)
如果您想接受来自非client
以外的任何用户的消息,则可以为check
编写一个wait_for_message
,例如:
check = lambda message: message.author != client.user
msg = await client.wait_for_message(check=check)