Code Monkey home page Code Monkey logo

qq-group-bot's Introduction

qq-official-bot

CI Docs npm version qq group

安装依赖

npm i qq-official-bot # or yarn add qq-official-bot

使用

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', // 频道私信事件
		'GUILD_MESSAGE_REACTIONS', // 频道消息表态事件
		'GUILDS', // 频道变更事件
		'GUILD_MEMBERS', // 频道成员变更事件
		'DIRECT_MESSAGE', // 频道私信事件
	], // (必填)
})
// 启动机器人
bot.start()

发送消息

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 获取用户详情
获取频道列表 getGuildList Guild[]
获取频道详情 getGuildInfo guild_id Guild
获取频道成员列表 getGuildMemberList guild_id Member[]
获取频道成员详情 getGuildMemberInfo guild_id member_id Member
获取子频道列表 getChannelList guild_id Channel[]
获取子频道详情 getChannelInfo guild_id channel_id Channel
发送频道消息 sendGuildMessage channel_id message -
发送频道私信消息 sendDirectMessage guild_id message -
发送群消息 sendGroupMessage group_id message -
发送私信消息 sendPrivateMessage user_openid message -
更多API文档信息待补充 -

qq-group-bot's People

Contributors

github-actions[bot] avatar lava081 avatar lc-cn avatar marrydream avatar timerainstarsky avatar xasyer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

qq-group-bot's Issues

二次重复监听了 websocket 事件

每次发送消息均会打印两次消息 info 日志。排查后发现是在鉴权完毕后重新创建 websocket 时未关闭初次创建的 websocket 导致的。

对此我做了相关修复来阻止重复创建 websocket / 二次创建时关闭先前的 websocket

运行环境:

  • qq-group-bot 版本: 1.0.7
  • nodejs 版本: v16.14.0

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.