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

@zhin.js/adapter-discord

v1.0.33

Published

Zhin.js adapter for Discord

Readme

@zhin.js/adapter-discord

Zhin.js Discord 适配器,支持 Discord 机器人的消息收发和服务器管理。

功能特性

  • 支持 Gateway(WebSocket)和 Interactions(HTTP Webhook)两种模式
  • 斜杠命令(Slash Commands)支持
  • 可配置 Intents 和默认活动状态
  • 服务器管理 AI 工具(通过 declareSkill 暴露给 AI)
  • 基于 discord.js 库

安装

pnpm add @zhin.js/adapter-discord discord.js

依赖

  • @zhin.js/http — HTTP 服务(Interactions 模式需要)

配置

Gateway 模式(推荐)

# zhin.config.yml
bots:
  - context: discord
    name: my-discord-bot
    token: ${DISCORD_BOT_TOKEN}
    # 可选配置
    # intents:
    #   - Guilds
    #   - GuildMessages
    #   - MessageContent
    # enableSlashCommands: true
    # defaultActivity:
    #   name: Zhin.js
    #   type: Playing

plugins:
  - adapter-discord
  - http

Interactions 模式(Webhook)

bots:
  - context: discord-interactions
    name: my-discord-bot
    token: ${DISCORD_BOT_TOKEN}
    applicationId: ${DISCORD_APP_ID}
    publicKey: ${DISCORD_PUBLIC_KEY}
    interactionsPath: /discord/interactions

TypeScript 配置

import { defineConfig } from 'zhin.js'

export default defineConfig({
  bots: [
    {
      context: 'discord',
      name: 'my-discord-bot',
      token: process.env.DISCORD_BOT_TOKEN!,
    }
  ],
  plugins: ['adapter-discord', 'http']
})

使用示例

注册命令

import { usePlugin, MessageCommand } from 'zhin.js'

const { addCommand } = usePlugin()

addCommand(
  new MessageCommand('ping')
    .desc('测试延迟')
    .action(() => 'Pong!')
)

消息中间件

import { usePlugin } from 'zhin.js'

const { addMiddleware } = usePlugin()

addMiddleware(async (message, next) => {
  if (message.$adapter === 'discord') {
    console.log('Discord 消息:', message.$content)
  }
  await next()
})

AI 工具(Skill)

适配器内置 Discord 服务器管理 Skill,工具供 AI 调用。

工具使用 Discord 的 Snowflake ID 格式标识 guild_iduser_idchannel_id

Discord 开发者配置

  1. 前往 Discord Developer Portal
  2. 创建应用并获取 Bot Token
  3. 开启 MESSAGE CONTENT INTENT(需要读取消息内容)
  4. 通过 OAuth2 URL 邀请 Bot 加入服务器
  5. Interactions 模式还需配置 Interactions Endpoint URL

许可证

MIT License