aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar evanwashere <github@evan.lol> 2022-07-05 13:53:57 -0400
committerGravatar Jarred Sumner <jarred@jarredsumner.com> 2022-07-05 11:45:28 -0700
commit91cff9473938ad5105422dc98838de1d25e4dd1b (patch)
treef3af4f90ad06e33287e0ec86625d6bcf96c0699a
parent0c9fb7e063d80358ddd7898ce7f45f3dc90aaecc (diff)
downloadbun-91cff9473938ad5105422dc98838de1d25e4dd1b.tar.gz
bun-91cff9473938ad5105422dc98838de1d25e4dd1b.tar.zst
bun-91cff9473938ad5105422dc98838de1d25e4dd1b.zip
add creating discord bots to readme
-rw-r--r--README.md30
-rw-r--r--examples/discord-interactions/bun_shim/server.js3
2 files changed, 32 insertions, 1 deletions
diff --git a/README.md b/README.md
index b64aaa399..fa8eddc1c 100644
--- a/README.md
+++ b/README.md
@@ -39,6 +39,8 @@ If using Linux, kernel version 5.6 or higher is strongly recommended, but the mi
- [Fast paths for Web APIs](#fast-paths-for-web-apis)
- [Using bun as a package manager](#using-bun-as-a-package-manager)
- [Using bun as a task runner](#using-bun-as-a-task-runner)
+- [Creating a Discord bot with Bun](#creating-a-discord-bot-with-bun)
+ - [Application Commands](#application-commands)
- [Using bun with Next.js](#using-bun-with-nextjs)
- [Using bun with single page apps](#using-bun-with-single-page-apps)
- [Using bun with Create React App](#using-bun-with-create-react-app)
@@ -350,6 +352,34 @@ Assuming a package.json with a `"clean"` command in `"scripts"`:
}
```
+## Creating a Discord bot with Bun
+
+### Application Commands
+
+> Application commands are native ways to interact with apps in the Discord client. There are 3 types of commands accessible in different interfaces: the chat input, a message's context menu (top-right menu or right-clicking in a message), and a user's context menu (right-clicking on a user).
+
+To get started you can use interactions template:
+
+```bash
+bun create discord-interactions my-interactions-bot
+cd my-interactions-bot
+```
+
+If you don't have a Discord bot/application yet, you can create one [here (https://discord.com/developers/applications/me)](https://discord.com/developers/applications/me).
+
+Afterwards you will need to get your bot's token, public key, and application id from application page and put them into `.env.example` file
+
+Then you can run the http server that will handle your interactions:
+
+```bash
+bun install
+mv .env.example .env
+
+bun run.js # listening on port 1337
+```
+
+Discord does not accept insecure http server, so you will need provide SSL certificate or put interactions server behind a secure reverse proxy. For development you can use ngrok/cloudflare tunnel to expose local port as secure URL.
+
## Using bun with Next.js
To create a new Next.js app with bun:
diff --git a/examples/discord-interactions/bun_shim/server.js b/examples/discord-interactions/bun_shim/server.js
index 5f32852a1..86fb9e542 100644
--- a/examples/discord-interactions/bun_shim/server.js
+++ b/examples/discord-interactions/bun_shim/server.js
@@ -19,11 +19,12 @@ export default class BunServer extends Server {
else throw new Error('BunServer not started');
}
- listen(port) {
+ listen(port, options = {}) {
const getHandler = () => this.#handler;
this.#server = Bun.serve({
port,
+ ...options,
async fetch(req) {
const handler = getHandler();