Netlify
Run an HTTP bot on Netlify Functions.
This page assumes you've read Serverless, and have a createBot() function like the one there.
Installing
In your project, install the bot and Netlify's types:
npm i @nyx-discord/http @discordjs/corenpm i -D @netlify/functionsWriting the function
Functions go in netlify/functions/, and config.path sets the URLs they're served at. Your secrets are in process.env
when the module loads, so the bot can be created right away. Netlify's context has a waitUntil, so pass it as is to keep
the function alive until your handlers finish:
import { } from '@nyx-discord/http';
import type { , } from '@netlify/functions';
const = (. as , false).(() => {
const = .();
return {
: (),
: (.()),
};
});
export default async (: , : ) => {
const { , } = await ;
const { } = new (.);
const = === '/webhook-events' ? : ;
return (, );
};
export const : = {
: ['/interactions', '/webhook-events'],
};Running locally
Put your secrets in .env:
APP_ID=...
DISCORD_PUBLIC_KEY=...
TOKEN=...npx netlify devTest it without Discord at http://localhost:8888/interactions, or
expose it with npx netlify dev --live and set that URL as your app's Interactions Endpoint URL.
Deploying
Add your secrets to the site, from your .env file:
npx netlify env:import .envnpx netlify deploy --prodRemember to deploy your commands too.
Setting the endpoint
On the Developer Portal, set your app's Interactions Endpoint URL to https://<site>.netlify.app/interactions,
and its Webhook Events URL (if you use them) to https://<site>.netlify.app/webhook-events.
Last updated on
