请给出对接go-cqhttp的Python代码
以下是对接go-cqhttp的Python代码示例:
import websocket
import json
# 连接go-cqhttp websocket
ws = websocket.create_connection("ws://127.0.0.1:6700/")
# 构造发送给go-cqhttp的数据
data = {
"action": "send_private_msg",
"params": {
"user_id": 123456,
"message": "Hello World!"
},
"echo": "test"
}
# 发送数据
ws.send(json.dumps(data))
# 接收响应
result = ws.recv()
# 处理响应数据
result = json.loads(result)
print(result)
# 关闭连接
ws.close()
以上代码实现了向指定QQ用户发送私聊消息的功能,其中需要将ws://127.0.0.1:6700/替换为go-cqhttp的websocket地址。具体的data数据格式和可用的action可以参考go-cqhttp文档。
原文地址: https://www.cveoy.top/t/topic/bA7t 著作权归作者所有。请勿转载和采集!