【问题标题】:discord.py bot: on_message detecting bot await send() messagesdiscord.py bot:on_message 检测机器人等待发送()消息
【发布时间】:2020-12-26 12:13:09
【问题描述】:

有没有办法检测用户(而不是机器人本身)何时发送了消息?我了解 on_message 事件允许与预期的命令/响应 (https://discordpy.readthedocs.io/en/latest/api.html) 进行比较,但对于我的项目,没有设置用户响应。这使得机器人每次检测到自己的消息时都会触发。我该如何解决?

【问题讨论】:

    标签: python discord.py discord.py-rewrite


    【解决方案1】:

    试试这个

    client = discord.Client()
    @bot.event
    async def on_message(message):
        if message.author == client.user:
            return
        #then write the code down here so if the person who send message is bot it wont count
    

    【讨论】:

    • 我试过了,但不幸的是 client.user 为我返回了 None 。 message.author 完美地返回了我的用户对象,但 client.user 不工作
    • 我所做的是 message.author != 'bot name'。我想这是一个解决方案,虽然不是最好的
    • 我的代码对我有用,请尝试使用命令 bot.commands
    猜你喜欢
    • 1970-01-01
    • 2020-11-04
    • 2020-10-10
    • 2022-01-03
    • 2021-10-13
    • 2020-09-08
    • 2021-10-14
    • 2021-01-26
    • 1970-01-01
    相关资源
    最近更新 更多