【发布时间】:2022-01-11 11:05:39
【问题描述】:
我对 Python 和 Discord.py 都很陌生,我正在尝试寻找如何让机器人同时等待用户的消息或反应。
我尝试将它们分开,但只是导致机器人在反应之前需要消息响应。
这是我正在尝试做的类似代码:
@bot.event
async def on_message(ctx):
if ctx.author == bot.user:
return
if ctx.content == "$respond":
message = await ctx.send("Waiting for response...")
while True:
try:
response = #Will wait for a message(Yes or No) or reaction(Check or Cross) from ctx.author for 30 secs
except asyncio.TimeoutError:
await message.edit(content=f"{ctx.author} did not respond anymore!")
break
if response.content == "yes":
await message.edit(content=f"{ctx.author} said yes!")
continue
elif response.content == "no":
await message.edit(content=f"{ctx.author} said nyo!")
continue
#These are reactions
elif str(response.emoji) == "✅":
await message.edit(content=f"ctx.author reacted ✅!")
continue
elif str(response.emoji) == "❌":
await messave.edit(content=f"Stopped listening to responses.")
break
【问题讨论】:
标签: python discord.py