You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
so you can click the green "Use this template" button on GitHub to create your own repo!
36
-
- Run `yarn` to install dependencies.
42
+
- Run `yarn` to install dependencies.
37
43
-[Create a new Discord application](https://discord.com/developers/applications).
38
44
- In the `Bot` settings of your Discord application, enable the `Message Content` intent.
39
45
- Fill out environment variables:
@@ -57,6 +63,7 @@ For this guide, I'll be using ngrok.
57
63
- In the Discord app settings, set `Interactions Endpoint URL` to `<YOUR_PUBLIC_TUNNELED_NGROK_URL>/api/interactions`.
58
64
Make sure to use the `https` URL!
59
65
- Save changes in the Discord app settings.
66
+
- Set the value of `ROOT_URL` in `.env.local` to your ngrok URL.
60
67
61
68
In order to verify your interactions endpoint URL, Discord will send a `PING` message to your bot, and the bot should
62
69
reply with a PONG (see `src/pages/api/interactions.ts`). If this is successful, your bot is ready to go!
@@ -104,26 +111,33 @@ commands!
104
111
105
112
-`src/app/api/interactions/route.ts`: This is the main route handler for the Interactions Endpoint. It receives
106
113
interactions from Discord and handles them accordingly.
107
-
-`src/discord/verify-incoming-request.ts`: Helper functions to verify incoming requests from Discord, as outlined in https://discord.com/developers/docs/interactions/receiving-and-responding#security-and-authorization.
114
+
-`src/discord/verify-incoming-request.ts`: Helper functions to verify incoming requests from Discord, as outlined in
-`src/app/page.tsx`: A basic web page. This could be your admin portal or whatever you'd like!
109
117
110
118
## Why Next.js (instead of Express, serverless, or Cloudflare Workers)?
111
119
112
-
NextBot leverages Next.js 13
113
-
[Route Handlers](https://nextjs.org/docs/app/building-your-application/routing/route-handlers) to receive and respond to
114
-
interactions. But why Next.js instead of something like Express or serverless (AWS Lambda)?
115
-
116
-
- Next.js is free and effortless to deploy on Vercel. Don't bother with trying to host your Express server
117
-
- Compared to serverless, edge is faster (no cold start) and cheaper (Edge Runtimes have more generous free tiers and
118
-
are cheaper per request)
119
-
120
-
A better comparison would be hosting a Discord bot on Cloudflare Workers, as shown in this
121
-
[official Discord tutorial](https://discord.com/developers/docs/tutorials/hosting-on-cloudflare-workers). The Next.js
122
-
edge runtime is built on Cloudflare Workers! Still, I think Next.js has some notable benefits:
123
-
124
-
- Next.js has the advantage of being a full web-app framework, making it easy to build an accompanying web app to go
125
-
along with your Discord app!
126
-
- Deploying on Vercel is not only simple, but it also scales out very effectively if you need to build a more complex
127
-
app (analytics, logging, integrations, etc.)
128
-
- You can use Next.js/Vercel features like [Dynamic Image Generation](NextBot is a template for building and deploying a Discord bot with Next.js. It runs 100% in the edge runtime so you get
- Requests to [PokeAPI](https://pokeapi.co/) are [cached automatically](https://nextjs.org/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating) by Next.js
143
+
- The dynamic image itself is also cached, so it only needs to be generated once.
0 commit comments