Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: 群聊发送的指令插件不响应 #835

Closed
SkyFutu opened this issue Jul 3, 2024 · 4 comments
Closed

[Bug]: 群聊发送的指令插件不响应 #835

SkyFutu opened this issue Jul 3, 2024 · 4 comments
Labels
bug? Bug或Bug修复相关
Milestone

Comments

@SkyFutu
Copy link

SkyFutu commented Jul 3, 2024

部署方式

手动部署

消息平台适配器

aiocqhttp(使用 OneBot 协议接入的)

系统环境

windows server 2019 江苏

Python环境

py 3.10.9

QChatGPT版本

v3.2.3

异常情况

刚从2.x升级到3.x,然后按照文档部署完后把文档里的开发模板(hello插件)放到plugin然后启动机器人,但是私聊发送指令hello就能响应,群聊发送就不会响应,后台是可以看到显示处理group的消息:hello的

日志信息

No response

启用的插件

bot] 所有插件(1):

#1 Hello
hello world
v0.1
作者: RockChinQ

@SkyFutu SkyFutu added the bug? Bug或Bug修复相关 label Jul 3, 2024
@RockChinQ RockChinQ added this to the 3.2.4 milestone Jul 4, 2024
@RockChinQ
Copy link
Owner

发发你的插件代码

@SkyFutu
Copy link
Author

SkyFutu commented Jul 4, 2024

发发你的插件代码

from pkg.plugin.context import register, handler, llm_func, BasePlugin, APIHost, EventContext
from pkg.plugin.events import *  # 导入事件类


"""
在收到私聊或群聊消息"hello"时,回复"hello, <发送者id>!"或"hello, everyone!"
"""


# 注册插件
@register(name="Hello", description="hello world", version="0.1", author="RockChinQ")
class HelloPlugin(BasePlugin):

    # 插件加载时触发
    def __init__(self, host: APIHost):
        pass

    # 异步初始化
    async def initialize(self):
        pass

    # 当收到个人消息时触发
    @handler(PersonNormalMessageReceived)
    async def person_normal_message_received(self, ctx: EventContext):
        msg = ctx.event.text_message  # 这里的 event 即为 PersonNormalMessageReceived 的对象
        if msg == "hello":  # 如果消息为hello

            # 输出调试信息
            self.ap.logger.debug("hello, {}".format(ctx.event.sender_id))

            # 回复消息 "hello, <发送者id>!"
            ctx.add_return("reply", ["hello, {}!".format(ctx.event.sender_id)])

            # 阻止该事件默认行为(向接口获取回复)
            ctx.prevent_default()

    # 当收到群消息时触发
    @handler(GroupNormalMessageReceived)
    async def group_normal_message_received(self, ctx: EventContext):
        msg = ctx.event.text_message  # 这里的 event 即为 GroupNormalMessageReceived 的对象
        if msg == "hello":  # 如果消息为hello

            # 输出调试信息
            self.ap.logger.debug("hello, {}".format(ctx.event.sender_id))

            # 回复消息 "hello, everyone!"
            ctx.add_return("reply", ["hello, everyone!"])

            # 阻止该事件默认行为(向接口获取回复)
            ctx.prevent_default()

    # 插件卸载时触发
    def __del__(self):
        pass

我用的就是文档里的示例,然后这个bug好像只在3.2.3出现,3.2.2就好了

@RockChinQ
Copy link
Owner

RockChinQ commented Jul 5, 2024

image

首先是得符合群内响应规则,才会进入这个 GroupNormalMessageReceived 事件。其次是,at 机器人的话,后面会自动添加一个空格,你要么改成 msg == " hello" 要么对 msg = msg.strip() 再去判断。

如果用的是前缀规则,这样是可以被响应的(前缀规则识别ai):
image

@SkyFutu
Copy link
Author

SkyFutu commented Jul 5, 2024

image 首先是得符合群内响应规则,才会进入这个 GroupNormalMessageReceived 事件。其次是,at 机器人的话,后面会自动添加一个空格,你要么改成 `msg == " hello"` 要么对 `msg = msg.strip()` 再去判断。

如果用的是前缀规则,这样是可以被响应的(前缀规则识别ai): image
好的谢谢,我看了下,写成了msg=="hello"绷不住了,谢谢解答qwq

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug? Bug或Bug修复相关
Projects
None yet
Development

No branches or pull requests

2 participants