Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/zhinjs/qq-official-bot
qq官方机器人开发SDK
https://github.com/zhinjs/qq-official-bot
group-bot guild-bot qqbot typescript
Last synced: about 2 months ago
JSON representation
qq官方机器人开发SDK
- Host: GitHub
- URL: https://github.com/zhinjs/qq-official-bot
- Owner: zhinjs
- License: mit
- Created: 2023-11-17T08:15:08.000Z (about 1 year ago)
- Default Branch: master
- Last Pushed: 2024-07-05T01:34:02.000Z (6 months ago)
- Last Synced: 2024-07-05T14:48:23.594Z (6 months ago)
- Topics: group-bot, guild-bot, qqbot, typescript
- Language: TypeScript
- Homepage: https://zhinjs.github.io/qq-official-bot/
- Size: 478 KB
- Stars: 20
- Watchers: 3
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# qq-official-bot
[![CI](https://github.com/zhinjs/qq-official-bot/actions/workflows/release.yaml/badge.svg?branch=master&event=push)](https://github.com/zhinjs/qq-official-bot/actions/workflows/release.yaml)
[![Docs](https://github.com/zhinjs/qq-official-bot/actions/workflows/docs.yaml/badge.svg?branch=master&event=push)](https://github.com/zhinjs/qq-official-bot/actions/workflows/docs.yaml)
[![npm version](https://img.shields.io/npm/v/qq-official-bot/latest.svg)](https://www.npmjs.com/package/qq-official-bot)
[![qq group](https://img.shields.io/badge/group-446290761-blue?style=flat-square&labelColor=FAFAFA&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAD4AAAA+CAMAAABEH1h2AAACB1BMVEX///8AAADoHx/6rgjnFhb/tQj9/f3/sggEAgLyICD//vztICAGBgbrHx8MDAwJCQn7rwj09PTi4uKbm5uBgYHvICAREREODg79sQgkJCT39/f/+/HExMT3q6tNTU37vTRFMQI4JwIgFgHt7e3r6+vd3d3b29u7u7uwsLDyenp4eHjxc3NZWVn//fj//PTf399vb29UVFQ8PDwuLi76uCUgICDfHh7oGh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Tu93m9Pv94xuLl3VT8ULx/8OaYASgyjN0c7I8fouLHjHYjF+8dGLx29/Erw1/cq8d3rw0O9MY59MAxGr3njEmj0Zg4u9Fuinf3nu8fuHDx4oWB/vO93XETWuSE8Jk9FLzZqPkjE8fZ7UYku53DnCRjszy9pZPT5CCuc4ssfsBoygU3GQ/I4sf7znJGzqSIogfO9h2Xo3c5YOz6pb7uc9pqObJaq9We6+67dH0MHLtkcCsIevll6ke1RBBVa351/myZ+vwSBFll8A4QtZf5oBXpzpZSpJXfmqcOvt+J67WX9EJHNh00SztqhYhrW2g70hzMwutBVE2xhK9c+ExxDXmoPgt3g3SaSDjtNAK37EGDVeSi464iAPkjJwSLwSFEOeFz+3iwyaZOSndFi3WllFK67ORdc3hb94jG7VzR3FL6vXTlQVnjerD5c66MQCMOVOIMDPsZqvZj0laJX9KYEUiigKNiOyBN0nEhvr3CgV6SzBxphE5O4iGglY63ojCfFHbH8oV4A8vU4lFsllX8C4zVMmzDQjwIHYXEPn4fDd/HE8sKOyCz69kJTDM4LYjS8CjgAjGYn2Cp86wjKE8HHapzbQC3ZUQ+FsEtHWAUFeIFDyinER9iVLQOD39hmakJD4zr6JzE84ivzzpNEM2r0+VN7YnXeHbe+vfqVjxnv060N5UrwvkfPWiWue/F51kk3MgKnjaGI2Y8MdxHM47nU74C3abTo3lCnzfqA+zgrDsScc86hHllNE8I6dro/LurQ3q902lxDlmGn/neANEb37NhyxBadur1Q1ff0t/e1Nbu8VRVbd5c1dXlOX3q5ImjR0+cPHXa09WF16o8nva2pnzl9MvKlyGVl5Xl5wtPop+y+TWC/jf9BuxZscgeRqlfAAAAAElFTkSuQmCC&logoColor=000000)](https://qm.qq.com/cgi-bin/qm/qr?_wv=1027&k=rYaL-gcqTjWYqwBs9TDoVSXKu-i5ircB&authKey=TO02faBOpfhmfkw3YQuUCG2HxUEwWCuFdMBf5nSt3qyWD%2FqaO453O9Dx%2BK8JwBdM&noverify=0&group_code=446290761)
## 安装依赖```shell
npm i qq-official-bot # or yarn add qq-official-bot
```## 使用
```js
const {Bot} = require('qq-official-bot')
// 创建机器人
const bot = new Bot({
appid: '', // qq机器人的appID (必填)
secret: '', // qq机器人的secret (必填)
sandbox: true, // 是否是沙箱环境 默认 false
removeAt: true, // 移除第一个at 默认 false
logLevel: 'info', // 日志等级 默认 info
maxRetry: 10, // 最大重连次数 默认 10
intents: [
'GROUP_AT_MESSAGE_CREATE', // 群聊@消息事件 没有群权限请注释
'C2C_MESSAGE_CREATE', // 私聊事件 没有私聊权限请注释
'GUILD_MESSAGES', // 私域机器人频道消息事件 公域机器人请注释
'PUBLIC_GUILD_MESSAGES', // 公域机器人频道消息事件 私域机器人请注释
'DIRECT_MESSAGE', // 频道私信事件
'MESSAGE_AUDIT', // 消息审核事件
'GUILD_MESSAGE_REACTIONS', // 频道消息表态事件
'GUILDS', // 频道变更事件
'GUILD_MEMBERS', // 频道成员变更事件
'DIRECT_MESSAGE', // 频道私信事件
], // (必填)
})
// 启动机器人
bot.start()
```## 发送消息
```javascript
const {Bot} = require('qq-official-bot')
const bot = new Bot({
// ...
})
// 只有启动后,才能发送
bot.start().then(() => {
// 频道被动回复
bot.on('message.guild', (e) => {
e.reply('hello world')
})
// 频道私信被动回复
bot.on('message.direct', (e) => {
e.reply('hello world')
})
// 群聊被动回复
bot.on('message.group', (e) => {
e.reply('hello world')
})
// 私聊被动回复
bot.on('message.private', (e) => {
e.reply('hello world')
})
// 主动发送频道消息
bot.sendGuildMessage(channel_id, 'hello')
// 主动发送群消息
bot.sendGroupMessage(group_id, 'hello')
// 主动发送私聊消息
bot.sendPrivateMessage(user_id, 'hello')
// 主动发送频道消息,注:需要先调用bot.createDirectSession(guild_id,user_id)创建私信会话,此处传入的guild_id为创建的session会话中返回的guild_id
bot.sendDirectMessage(guild_id, 'hello')
})
```## API
| 功能 | 方法名 | 参数1 | 参数2 | 参数3 | 参数4 | 返回值 |
|--------------|--------------------|-------------|------------|-----|-----|------------------------------------------------------------------------------------------------------------------|
| 获取当前机器人信息 | getSelfInfo | | | | | 见[获取用户详情](https://bot.q.qq.com/wiki/develop/api-231017/server-inter/channel/manage/user/me.html#content-type) |
| 获取频道列表 | getGuildList | | | | | [Guild](https://bot.q.qq.com/wiki/develop/api-231017/server-inter/channel/manage/guild/model.html)[] |
| 获取频道详情 | getGuildInfo | guild_id | | | | [Guild](https://bot.q.qq.com/wiki/develop/api-231017/server-inter/channel/manage/guild/model.html) |
| 获取频道成员列表 | getGuildMemberList | guild_id | | | | [Member](https://bot.q.qq.com/wiki/develop/api-231017/server-inter/channel/role/member/model.html#member)[] |
| 获取频道成员详情 | getGuildMemberInfo | guild_id | member_id | | | [Member](https://bot.q.qq.com/wiki/develop/api-231017/server-inter/channel/role/member/model.html#member) |
| 获取子频道列表 | getChannelList | guild_id | | | | [Channel](https://bot.q.qq.com/wiki/develop/api-231017/server-inter/channel/manage/channel/model.html#channel)[] |
| 获取子频道详情 | getChannelInfo | guild_id | channel_id | | | [Channel](https://bot.q.qq.com/wiki/develop/api-231017/server-inter/channel/manage/channel/model.html#channel) |
| 发送频道消息 | sendGuildMessage | channel_id | message | | | - |
| 发送频道私信消息 | sendDirectMessage | guild_id | message | | | - |
| 发送群消息 | sendGroupMessage | group_id | message | | | - |
| 发送私信消息 | sendPrivateMessage | user_openid | message | | | - |
| 更多API文档信息待补充 | | | | | | - |