Vercel
Run an HTTP bot on Vercel Functions.
This page assumes you've read Serverless, and have a createBot() function like the one there.
If your bot lives in a Next.js app, use a route handler instead.
Installing
In your project, install the bot and Vercel's helpers:
npm i @nyx-discord/http @discordjs/core @vercel/functionsWriting the function
Every file in api/ is a function, served at its path. Your secrets are in process.env when the module loads, so the bot
can be created right away. Pass waitUntil from @vercel/functions, so the function stays alive until your handlers finish:
import { } from '@nyx-discord/http';
import { } from '@vercel/functions';
const = (. as , false).(() =>
(.()),
);
export async function (: ) {
return (await )(, { });
}For webhook events, add an api/webhook-events.ts that does the same with toFetchHandler(bot.getClient().getWebhookEventHandler()).
Running locally
Put your secrets in .env.local:
APP_ID=...
DISCORD_PUBLIC_KEY=...
TOKEN=...npx vercel devTest it without Discord at http://localhost:3000/api/interactions, or
expose it with a tunnel and set the tunnel's URL as your app's Interactions Endpoint URL.
Deploying
Add your secrets to the project, for each of APP_ID, DISCORD_PUBLIC_KEY and TOKEN:
npx vercel env add TOKEN productionnpx vercel deploy --prodRemember to deploy your commands too.
Setting the endpoint
On the Developer Portal, set your app's Interactions Endpoint URL to https://<project>.vercel.app/api/interactions,
and its Webhook Events URL (if you use them) to https://<project>.vercel.app/api/webhook-events.
Last updated on
