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.81

Published

Zhin.js adapter for Discord

Downloads

2,516

Readme

@zhin.js/adapter-discord

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

功能特性

  • 📦 单一适配器context: discord,通过 connection 选择连接方式
  • 🌐 Gatewayconnection: gateway):WebSocket 网关,支持群管、消息、斜杠命令等
  • 📮 Interactionsconnection: interactions):HTTP 交互端点,斜杠命令等
  • 可配置 Intents 和默认活动状态
  • 服务器管理 AI 工具(仅 Gateway 支持)
  • 基于 discord.js 库

安装

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

Interactions 模式需同时启用 @zhin.js/http

配置

所有 Bot 使用 同一 context:discord,通过 connection 区分连接方式。

Gateway(connection: gateway,默认)

plugins:
  - "@zhin.js/adapter-discord"

bots:
  - context: discord
    connection: gateway
    name: my-discord-bot
    token: "${DISCORD_BOT_TOKEN}"
    # 可选: intents, enableSlashCommands, defaultActivity, slashCommands

Interactions(connection: interactions)

plugins:
  - "@zhin.js/http"
  - "@zhin.js/adapter-discord"

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

未写 connection 时默认为 gateway

使用示例

注册命令

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