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

发送群消息的封装有问题 #180

Open
qq809326636 opened this issue Apr 17, 2024 · 1 comment
Open

发送群消息的封装有问题 #180

qq809326636 opened this issue Apr 17, 2024 · 1 comment

Comments

@qq809326636
Copy link

  • botpy 版本:1.2.3

发送群消息代码如下

  async def post_group_message(
      self,
      group_openid: str,
      msg_type: int = 0,
      content: str = None,
      embed: message.Embed = None,
      ark: message.Ark = None,
      message_reference: message.Reference = None,
      media: message.Media = None,
      msg_id: str = None,
      msg_seq: int = 1,
      event_id: str = None,
      markdown: message.MarkdownPayload = None,
      keyboard: message.Keyboard = None,
  ) -> message.Message:
      """
      发送消息。

      注意:
      - 要求操作人在该群具有发送消息的权限。
      - 发送成功之后,会触发一个创建消息的事件。
      - 被动回复消息有效期为 5 分钟
      - 发送消息接口要求机器人接口需要链接到websocket gateway 上保持在线状态

      Args:
        group_openid (str): 您要将消息发送到的群的 ID。
        msg_type (int): 消息类型:0 是文本,1 图文混排,2 是 markdown,3 ark,4 embed,7 media 富媒体
        content (str): 消息的文本内容。
        embed (message.Embed): embed 消息,一种特殊的 ark
        ark (message.Ark): ark 模版消息
        message_reference (message.Reference): 对消息的引用。
        media (message.Media): 富媒体消息
        msg_id (str): 您要回复的消息的 ID。
        msg_seq (int): 回复消息的序号,与 msg_id 联合使用,默认是1。相同的 msg_id + msg_seq 重复发送会失败。
        event_id (str): 您要回复的消息的事件 ID。
        markdown (message.MarkdownPayload): markdown 消息
        keyboard (message.Keyboard): keyboard 消息

      Returns:
        message.Message: 一个消息字典对象。
      """
      payload = locals()
      payload.pop("self", None)
      route = Route("POST", "/v2/groups/{group_openid}/messages", group_openid=group_openid)
      return await self._http.request(route, json=payload)

代码中 payload = locals() 这句话会导致 payload.py

class JsonPayload(BytesPayload):
    def __init__(
        self,
        value: Any,
        encoding: str = "utf-8",
        content_type: str = "application/json",
        dumps: JSONEncoder = json.dumps,
        *args: Any,
        **kwargs: Any,
    ) -> None:

        super().__init__(
            dumps(value).encode(encoding),
            content_type=content_type,
            encoding=encoding,
            *args,
            **kwargs,
        )

这段序列化 dumps(value)ValueError: Circular reference detected

@liaoyanglay
Copy link
Collaborator

没太懂这个错误是什么导致的,能否再描述详细些,或者贴上完整的代码

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants