|
8 | 8 |
|
9 | 9 | It handles various interactions and organizes them into modular routes, making your bot's code cleaner, easier to understand, and easier to maintain. It works seamlessly in both serverless and persistent server environments. |
10 | 10 |
|
11 | | -**Currently in development** |
| 11 | +The core is production-ready and can be used in your new http interaction bots. |
| 12 | + |
| 13 | +```js |
| 14 | +import Client from "discord.https"; |
| 15 | +import NodeAdapter from "@discordhttps/nodejs-adapter"; |
| 16 | +import { InteractionResponseType } from "discord-api-types/v10"; |
| 17 | + |
| 18 | +const client = new Client({ |
| 19 | + token: "YOUR BOT TOKEN", |
| 20 | + publicKey: "YOUR PUBLIC KEY", |
| 21 | + httpAdapter: new NodeAdapter(), |
| 22 | +}); |
| 23 | + |
| 24 | +client.commandcommand( |
| 25 | + (builder) => builder.setName("hi").setDescription("reply hello!"), |
| 26 | + async (interaction, client, _, res) => { |
| 27 | + res.writeHead(200, { |
| 28 | + "Content-Type": "application/json", |
| 29 | + }); |
| 30 | + const username = interaction.user |
| 31 | + ? interaction.user.global_name |
| 32 | + : interaction.member.user.global_name; |
| 33 | + res.end( |
| 34 | + JSON.stringify({ |
| 35 | + type: InteractionResponseType.ChannelMessageWithSource, |
| 36 | + data: { |
| 37 | + content: `Hello! ${username}`, |
| 38 | + }, |
| 39 | + }) |
| 40 | + ); |
| 41 | + } |
| 42 | +); |
| 43 | + |
| 44 | +await client.listen("interactions", 3000, () => { |
| 45 | + console.log( |
| 46 | + "Listening for interactions on port 3000 at the /interactions endpoint" |
| 47 | + ); |
| 48 | +}); |
| 49 | +``` |
| 50 | + |
| 51 | +**You can view example/reference implementations here:** |
| 52 | + |
| 53 | +- Nodejs Runtime: [https://github.com/discordhttps/nodejs-example](https://github.com/discordhttps/nodejs-example) |
| 54 | +- V8 isolates runtime(Cloudflare Workers): [https://github.com/discordhttps/cloudflare-example](https://github.com/discordhttps/cloudflare-example) |
| 55 | + |
| 56 | +> Note: Utility methods such as <interaction>.editReply() and <interaction>.deferReply() are currently in development, so you won’t need to manually handle the raw response object in the future. |
12 | 57 |
|
13 | 58 | ### To do: |
14 | 59 |
|
15 | | -- [ ] Build structures → reference: https://www.npmjs.com/package/@discordjs/structures |
| 60 | +- [ ] Build structures → reference: [discord.js - structures](https://github.com/discordjs/discord.js/tree/main/packages/discord.js/src/structures) |
16 | 61 | - [ ] Build a simplified `npx create-app` command [in progress] |
17 | 62 | - [ ] Implement tests |
18 | 63 | - [x] HTTP adapters to support all hosting environments. Currently implemented: Node.js adapter for [Node.js runtime](https://github.com/discord-http/nodejs-adapter) and [Cloudflare adapter for V8 isolates runtime](https://github.com/discord-http/cloudflare-adapter) |
|
0 commit comments