Tips
Error: npm run register
Error when register.js
cannot be executed, regardless of the success or failure of command registration.
Please consider the following modifications (Either one or a combination):
- package.json
"type": "module",
- tsconfig.json
"moduleResolution": "Node",
"moduleResolution": "Bundler",
- register.ts
- Add
.js
when importing from other files
import { commands } from './commands.js'
- Add
- Environment Update
- Use Node v23.6.0 or Bun
If you still can’t resolve the issue:
- Give up on file splitting
- Don’t split
register.ts
intocommands.ts
etc.
- Don’t split
- Create a URL endpoint for command registration
- Use Hono or similar to create routing and a registration URL
- As a precaution, apply basic authentication or similar
Developing with npm run dev
While production deployment is done on platforms like Cloudflare Workers, if you want to develop locally, please refer to this guide.
As a library developer, we do not recommend using npm run dev
(unless you have a specific reason to do so).
Instead, consider one of the following alternatives:
- Create a separate Bot account for development
- Register development-only commands for your production Bot that are only available on development servers
Error: wrangler dev
An error that occurs when accessing the URL endpoint for command registration in the development environment.
Try the following fixes:
- Rename the
.env
file to.dev.vars
- Add
.dev.vars
to.gitignore
(if not already present)
Validation error when registering URL
Error when registering a URL in the INTERACTIONS ENDPOINT URL of the Discord dashboard.
Try the following fix:
- Change the
_
(underscore) in the URL you’re registering to-
(hyphen)aaa_bbb.user.workers.dev
->aaa-bbb.user.workers.dev
Notes on Emojis
new Button('button-1', 'Button').emoji('🔄')
When setting an emoji and sending it to Discord, there may be no response.
This is likely because Discord may not properly recognize the emoji Unicode’s variation selector.
Emoji list that appears to exclude variation selectors
Tips for various environments (β)
Hono
const discord = new DiscordHono()discord.command('hello', c => c.res('Discord World'))
const hono = new Hono()hono.get('/', c => c.text('Hono World'))hono.mount('/interaction', discord.fetch)
- Browser
https://YOUER_DOMAIN.com
-> Display:Hono World
- Discord Bot
/hello
-> Response:Discord World
- Discord Interaction Endpoint
- Register URL:
https://YOUER_DOMAIN.com/interaction
- Register URL:
Deno Deploy
import { DiscordHono } from 'npm:discord-hono'
const app = new DiscordHono()app.command('ping', c => c.res('Pong!!'))
Deno.serve(app.fetch)
Fastly Compute
import { env } from 'fastly:env'import { DiscordHono } from 'discord-hono'
const app = new DiscordHono({ discordEnv: () => ({ APPLICATION_ID: env('DISCORD_APPLICATION_ID'), PUBLIC_KEY: env('DISCORD_PUBLIC_KEY'), TOKEN: env('DISCORD_TOKEN'), }),}).command('ping', c => c.res('Pong!!'))
addEventListener('fetch', event => event.respondWith(app.fetch(event.request, undefined, event)),)