discord.py阻止bot作为命令读取消息

时间:2020-09-21 13:45:19

标签: python-3.x async-await discord.py

机器人会要求用户选择一种类型。我已经使用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.")```

1 个答案:

答案 0 :(得分:0)

类似的东西对您有用吗?

if not msg.content.startswith('.'): selection = msg.content.title()