Skip to content

Vercel Functions

@discord0/adapter-vercel deploys your app as a Vercel Function with the Vercel CLI.

Terminal window
npx discord0 init my-bot --adapter vercel

.discord0/vercel contains:

  • api/interactions.mjs,
  • a package.json that depends on @vercel/functions and pins Node.js 22,
  • a vercel.json that rewrites /interactions and each webhook path to the function, and
  • a .vercelignore that keeps source maps out of the upload.

The Vercel CLI asks you to log in and link a project on the first deploy. Deploys are previews unless you pass --prod:

Terminal window
npx discord0 deploy --prod

Use the production domain for your Interactions Endpoint URL. Preview URLs change with each deploy and may be behind Deployment Protection, which would block Discord’s requests.

Add DISCORD_PUBLIC_KEY and DISCORD_BOT_TOKEN in Project Settings → Environment Variables, or from .discord0/vercel:

Terminal window
cd .discord0/vercel
npx vercel env add DISCORD_PUBLIC_KEY production
npx vercel env add DISCORD_BOT_TOKEN production

Variables apply to new deployments, so deploy again after adding them.

The adapter passes deferred work to waitUntil() from @vercel/functions.

When you leave autoDeferAfterMs unset, the adapter defaults it to 1000ms. Cold starts often take 0.7 to 1.6 seconds before the handler runs, and the lower default still fits the acknowledgement inside Discord’s 3-second window. Set autoDeferAfterMs on new Discord() to override. See Deferred work.

  • The function’s maximum duration. Promises passed to waitUntil share the function’s timeout. Vercel cancels them if the function times out.
  • With fluid compute, on by default, the default maximum duration is 300 seconds on every plan. Hobby can’t raise it. Pro and Enterprise can raise it to 800 seconds. (Duration limits)
  • deploy rewrites vercel.json each time, so set a longer duration as the project default in Project Settings → Functions rather than in the generated file.

Each scheduled task becomes a Cron Job in vercel.json that calls /api/tasks?task=<name>, served by api/tasks.mjs. Set CRON_SECRET in the project. Vercel sends it in the Authorization header of each cron request, and the route refuses requests without it. Cron Jobs run in UTC, on production deployments only. Hobby allows only schedules that run at most once a day, and runs them anywhere within the scheduled hour.