【问题标题】:discord.py prevent bot from reading message as a commanddiscord.py 阻止机器人将消息作为命令读取
【发布时间】: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


    【解决方案1】:

    这样的东西对你有用吗?

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

    【讨论】:

    • 我试过了,但命令最终还是被执行了。
    猜你喜欢
    • 2022-08-05
    • 2019-12-23
    • 1970-01-01
    • 2021-06-02
    • 2021-07-14
    • 2020-10-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多