REST API
There are 4 ways to use Discord’s REST API:
c.rest
createRest(c.env.DISCORD_TOKEN)
- Other libraries (such as @discordjs/rest)
- Implement your own using
fetch()
1 and 2 behave the same way.
Since REST API is essentially separable, any implementation method is acceptable.
About c.rest
If you’re using createRest()
, please replace it accordingly.
import { _channels_$_messages } from 'discord-hono'
await c.rest('POST', _channels_$_messages, [channel_id], { content: 'this is rest',})
The first argument is the Method from the official documentation.
The second argument is defined here.
For the third argument, enter the variable parts enclosed in {}
within the Path as an array.
The fourth argument and subsequent arguments are the required data.
await c.rest('POST', '/channels/{channel.id}/messages', [channel_id], { content: 'this is rest',})
The first argument is the Method from the official documentation.
The second argument is the Path from the official documentation. Copy it as is.
For the third argument, input the variable parts enclosed in {}
within the Path as an array.
The fourth argument and subsequent arguments are the necessary data.
The REST API client provided by Discord Hono is a lightweight fetch wrapper with type safety.
Since it focuses on optimization for edge environments, complex features like automatic rate limit handling are intentionally omitted.