botpy icon indicating copy to clipboard operation
botpy copied to clipboard

发送@消息时完全没有反应

Open lidongxun967 opened this issue 1 year ago • 5 comments

# -*- coding: utf-8 -*-
import asyncio
import os

import botpy
from botpy import logging
from botpy.ext.cog_yaml import read
from botpy.message import Message

test_config = read(os.path.join(os.path.dirname(__file__), "config.yaml"))

_log = logging.get_logger()


class MyClient(botpy.Client):
    async def on_ready(self):
        _log.info(f"robot 「{self.robot.name}」 on_ready!")

    async def on_at_message_create(self, message: Message):
        _log.info(message.author.avatar)
        if "sleep" in message.content:
            await asyncio.sleep(10)
        _log.info(message.author.username)
        await message.reply(content=f"机器人{self.robot.name}收到你的@消息了: {message.content}")
    async def on_message_create(self, message: Message):
        _log.info(message.author.username)
        await message.reply(content=f"机器人{self.robot.name}收到你的消息了: {message.content}")

if __name__ == "__main__":
    # 通过预设置的类型,设置需要监听的事件通道
    # intents = botpy.Intents.none()
    # intents.public_guild_messages=True

    # 通过kwargs,设置需要监听的事件通道
    intents = botpy.Intents(public_guild_messages=True)
    client = MyClient(intents=intents,is_sandbox=True)
    client.run(appid=test_config["appid"], secret=test_config["secret"])

启动后在添加了机器人的群中@机器人没有反应,log中也无提示

lidongxun967 avatar Aug 18 '24 03:08 lidongxun967

启动时是正常的

[INFO]  (client.py:162)_bot_login       [botpy] 登录机器人账号中...
[INFO]  (robot.py:65)update_access_token        [botpy] access_token expires_in 5696

[INFO]  (client.py:181)_bot_init        [botpy] 程序启动...
[INFO]  (connection.py:60)multi_run     [botpy] 最大并发连接数: 1, 启动会话数: 1    
[INFO]  (client.py:242)bot_connect      [botpy] 会话启动中...
[INFO]  (gateway.py:115)ws_connect      [botpy] 启动中...
[INFO]  (gateway.py:142)ws_identify     [botpy] 鉴权中...
[INFO]  (gateway.py:85)on_message       [botpy] 机器人「樱落-测试中」启动成功!     
[INFO]  (gateway.py:223)_send_heart     [botpy] 心跳维持启动...
[INFO]  (demo_at_reply.py:17)on_ready   robot 「樱落-测试中」 on_ready!

lidongxun967 avatar Aug 18 '24 03:08 lidongxun967

同问

QyuJ123456 avatar Aug 19 '24 19:08 QyuJ123456

要改成on_group_at_message_create

Brian90709 avatar Aug 25 '24 16:08 Brian90709

要改成on_group_at_message_create

没用啊

wzn2009 avatar Sep 06 '24 09:09 wzn2009

解决了,群聊中@无反应的解决方法看这个项目: https://github.com/tencent-connect/botpy/blob/master/examples/demo_group_reply_text.py

wzn2009 avatar Sep 06 '24 09:09 wzn2009

这不是自动@吗???

John-Smiths avatar Sep 15 '24 08:09 John-Smiths

问题已经解决

lidongxun967 avatar Oct 14 '24 15:10 lidongxun967