Netlify Functions
@discord0/adapter-netlify deploys your app as a Netlify Function with the
Netlify CLI.
npx discord0 init my-bot --adapter netlifyWhat deploy generates
Section titled “What deploy generates”.discord0/netlify contains:
functions/interactions.mjs, which serves/interactionsand each webhook path,- a
netlify.toml, - a placeholder
public/index.html, and - a
package.jsonthat setsengines.nodeto22.x.
The Netlify CLI asks you to log in and link a project on the first deploy.
Deploys are drafts unless you pass --prod:
npx discord0 deploy --prodUse the production URL for your Interactions Endpoint URL.
Credentials
Section titled “Credentials”Add DISCORD_PUBLIC_KEY and DISCORD_BOT_TOKEN in Project configuration →
Environment variables, or from .discord0/netlify:
cd .discord0/netlifynpx netlify-cli env:set DISCORD_PUBLIC_KEY <public key>npx netlify-cli env:set DISCORD_BOT_TOKEN <bot token>Variables apply to new deploys, so deploy again after setting them.
Deferred work
Section titled “Deferred work”The adapter passes deferred work to the function’s
context.waitUntil().
When you leave autoDeferAfterMs unset, the adapter defaults it to 500ms.
A cold start can use most of Discord’s 3-second window before the handler
runs, and the lower default still leaves room for the acknowledgement. Set autoDeferAfterMs on
new Discord() to override. See
Deferred work.
- 60 seconds in total. A function can run until its execution time limit,
and that limit includes all
waitUntilwork. Synchronous functions have a 60-second limit, which you can’t change. (Default values) - Netlify bills and logs the full duration, until the deferred work finishes.
Netlify’s background functions run for up to 15 minutes, but they answer with
an immediate 202 and no body, which Discord doesn’t accept as an interaction
response. For longer jobs, trigger a background function from your handler
and edit the reply from there.
Scheduled tasks
Section titled “Scheduled tasks”Each scheduled task becomes a scheduled function,
functions/task-<name>.mjs. Scheduled functions run in UTC, on published
deploys only, and stop after 30 seconds.