【发布时间】:2021-01-07 15:02:43
【问题描述】:
机器人要求用户选择一种类型。我使用了 client.wait_for() 函数来获取用户输入。命令前缀是'.'如果用户键入以“.”开头的消息,我不希望机器人将其作为命令读取并执行该命令。我怎么做? 这是代码:
@client.command()
async def search(ctx):
try:
await ctx.send("Enter '"+selected_type[0]+"' or '"+selected_type[1]+"' to search for required type")
msg = await client.wait_for('message', timeout=10, check=lambda message: message.author == ctx.author)
selection = msg.content.title()
except asyncio.TimeoutError as e: #if user does not give input in 10 sec, this exception occurs
await ctx.send("Too slow")
except:
await ctx.send("Search failed.")```
【问题讨论】:
标签: python-3.x async-await discord.py