基于 BotRoot 的 JavaScript / TypeScript 开黑啦 Bot 开发框架。
import { KBotify } from 'kbotify';
const bot = new KBotify({
mode: 'webhook', // Webhook 模式
port: 12345, // 回调监听端口
token: 'your token',
verifyToken: 'your verify token',
key: 'your encrypt key',
ignoreDecryptError: false, // 是否忽略消息解密错误 如果需要可以改为true
});
bot.connect(); // 启动 Bot
你也可以使用仓库模板
参考其中的 src/commands/echo 文件夹即可。修改 src/configs 文件夹下 template-auth.ts 中的内容,并重命名为 auth.ts 即可开始使用。
可参考文档链接
当前仅支持用"." "。"和@机器人 三种开头方式。未来考虑增加多种前缀,但是为了方便统一前缀,这里可能不会做修改,需要大家自行修改。
bot.processMsg=()=>{}
添加 Command
bot.addCommands(echoMenu, echoKmd);
添加 Alias
bot.addAlias(echoMenu, '复读', '重复');
启动 Bot
bot.connect();
bot.message.on('text', (msg) => {});
bot.event.on('system', (event) => {});
请查看 src/commands 下的示例。
import { MenuCommand } from 'commands/shared/menu';
import { BaseData } from 'commands/shared/types';
import { echoKmd } from './echo.kmd.app';
class EchoMenu extends MenuCommand {
code = 'echo';
trigger = 'echo';
help = '目前只有`.echo kmd`一个指令。';
intro = '复读菜单';
}
export const echoMenu = new EchoMenu(echoKmd);
echoMenu.addAlias(echoKmd, 'kmarkdown', '富文本');
import { AppCommand } from 'commands/shared/app';
import { AppFunc } from 'commands/shared/app.types';
import { BaseData } from 'commands/shared/types';
class EchoAll extends AppCommand {
code = 'all';
trigger = 'all';
help = '`.echo all 时间`';
intro = '在指定时间内复读全部文字';
func: AppFunc<BaseSession> = async (session) => {
session.setTextTrigger('', 6e4, (msg) => session.sendOnly(msg.content));
return session.reply('将会复读下一次任意内容,1min有效', session);
};
}
export const echoAll = new EchoAll();
可以使用官方提供的卡片消息编辑器
完成编辑后,复制右侧自动生成的代码,然后把每张卡片使用const cardObject = new Card({...这里是卡片的内容})
进行生成即可,发送的时候使用session.sendCard(cardObject)
或session.sendCardTemp(cardObject)
进行发送。
你也可以直接复制自动生成的代码,使用session.sendCard([cardObjects])
进行发送,具体可参考 src/commands 文件夹下的示例。
update message
中使用 card
了\_botInstance
重命名为 client
,增加了 deprecate
标志Card.toString()
增加了选项,可以输出带有方括号或无方括号的 string。0.2.2
版本将会覆盖 99% APIclass Card
,废弃了之前使用 parser
的模式,提供更好的卡片消息操作性能。GuildSession.awaitMessage
,允许开发者等待用户在当前频道的下一条消息。collecter
,允许开发者在一定时间内收集频道内的消息,并且自定义停止的 trigger。mention
、reply
错误BaseData
为 BaseSession
,简化了消息回复流程,增加对一次性文字 trigger 的支持。Generated using TypeDoc