npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

onebot.js

v0.3.1

Published

onebot SDK for Node

Readme

onebot.js

OneBot 11 正向 WebSocket 客户端 SDK(TypeScript、仅 ESM)。

以 OneBot 11 标准协议为主,同时附带 NapCat 扩展 API(与标准协议不冲突,故直接收录)。注意:扩展 API 仅在 NapCat 上保证可用,其他实现调用时可能报错,兼容边界后续会改进。

本项目 fork 自 node-napcat-ts(MIT), 感谢原作者 @huankong233 及各位贡献者。

安装

pnpm add onebot.js

要求 Node.js >= 22。本包仅支持 ESM(import);CJS 环境请使用 await import('onebot.js')。

快速开始

connect() 建立正向连接:连接成功后才返回 OneBotClient 对象; 按 reconnection 的预算自动重试,全部失败会直接抛出异常,由调用者处理。

import { connect, Structs } from 'onebot.js'

const bot = await connect({
  baseUrl: 'ws://127.0.0.1:3001',
  accessToken: 'your token', // 以 query 参数追加(OneBot 11 正向 WS 约定),可选
  // reconnection: { enable: true, attempts: 10, delay: 5000 }, // 自动重连,可选
  // logger: console, // 日志出口,可选;省略时默认使用 console(自定义 logger 需带 info/warn/debug)
})

// 收消息(事件名支持 message / notice / request / meta_event 及分层子事件)
bot.on('message', (context) => {
  console.log(context.sender.nickname, context.raw_message)
})

// 发消息
bot.on('message', async (context) => {
  if (context.raw_message === 'echo') {
    await bot.send_msg({ ...context, message: [Structs.text('pong')] })
  }
})

也可以不经过 connect(),直接实例化并自行管理生命周期:

import { OneBotClient } from 'onebot.js'

const bot = new OneBotClient({ baseUrl: 'ws://127.0.0.1:3001' })
await bot.connect()   // 等待连接建立
await bot.disconnect() // 主动断开

更多用法见 docs:如何使用 · 绑定事件 · 调用接口 · 结构体构造器。

文档

License

MIT