Access Discord Bot
Overview
The Grape Access Discord Bot assigns and removes Discord roles based on on-chain Grape Access gate checks.
It is designed for serverless deployment on Vercel and integrates with:
Discord Interactions (slash commands)
Grape Access + Verification + Reputation programs (Solana)
Verification callback events (wallet linking + auto-sync)
Scheduled and queued revalidation jobs
What The Bot Does
Maps a
gate_idto a Discord role per guild.Builds verification links for members.
Stores the latest verified wallet per Discord user and guild.
Runs gate checks and applies role changes.
Supports manual identity overrides for hard-to-resolve verification cases.
Runs both:
callback-driven sync after verification
periodic cron revalidation
High-Level Flow
Admin runs
/setup-gateto map a gate and role.Member runs
/verifyand completes verification.External verifier calls
/api/verification/linkwithdiscordUserId,walletPubkey, andguildId.Bot stores the wallet link and syncs mapped gate(s).
Bot applies role updates based on pass/fail result.
Cron (
/api/cron/revalidate) keeps memberships fresh over time.
Slash Commands
/setup-gate gate_id pass_role_id [guild_id] [dao_id] [verification_dao_id] [reputation_dao_id] [fail_action]
Create/update gate-to-role mapping
Administrator or Manage Server
/verify
Return verification/access links for configured gates
Everyone
/check
Run manual check against latest linked wallet
Administrator
/debug-identity gate_id
Debug verification identity/link account resolution
Administrator
/link-identity gate_id identity_pda [link_pda]
Manually set identity/link override
Administrator
/link-wallet wallet
Manually link wallet (testing/admin)
Administrator
/reset-me
Remove latest wallet link + identity overrides
Administrator
/sync-gate gate_id [dry_run]
Queue full-guild sync and run immediate requester check
Admin/Moderator (Manage Roles, Moderate Members, or Administrator)
HTTP Endpoints
Discord Interactions
POST /api/discord/interactionsAlias:
POST /api/interactionsValidates Discord Ed25519 signature and processes slash commands.
Verification Callback
POST/GET /api/verification/linkAliases:
/api/discord/callback/api/verification/add/api/verification/verify
Required fields:
discordUserIdwalletPubkeyguildId(unlessgateIdmaps to exactly one guild)
Optional:
gateId,verifiedAt,source,identityPda,linkPda
Security:
Optional shared secret via
VERIFY_SHARED_SECRET:x-verify-secretheaderAuthorization: Bearer <secret>verify_secretquery param
Cron Revalidation
GET /api/cron/revalidateOptional
CRON_SECRETvia bearer tokenProcesses queued
/sync-gatejobs and periodic gate revalidation.
RPC Diagnostics
GET /api/rpc/pingOptional
?endpoint=<rpc_url>Returns both
fetchand@solana/web3.jsprobe results.
Storage Model
Primary runtime store is Vercel KV. If KV env vars are missing, bot falls back to in-memory state.
Stored entities:
Gate mappings (
guildId + gateId)Latest wallet link per (
guildId + discordUserId)Identity overrides (
guildId + gateId + discordUserId)Sync job queue
Check results history
Last revalidation run timestamps
Use KV_KEY_PREFIX to isolate this bot when sharing KV.
Environment Variables
Required:
DISCORD_APP_ID(orDISCORD_CLIENT_ID)DISCORD_BOT_TOKEN(orDISCORD_TOKEN)DISCORD_PUBLIC_KEYACCESS_FRONTEND_BASE_URL
Recommended:
KV_REST_API_URLKV_REST_API_TOKENVERIFY_SHARED_SECRETCRON_SECRETRPC_ENDPOINT
Behavior controls:
CHECK_MODE(simulateby default)BASIC_IDENTITY_CHECK_MODE(trueby default)DEFAULT_RECHECK_INTERVAL_SECMAX_SYNC_JOBS_PER_CRONMAX_USERS_PER_SYNCRPC_REQUEST_TIMEOUT_MSDRY_RUN_SYNCBOOTSTRAP_GATES_JSON
Deployment Notes (Vercel)
Project uses Vercel Functions (
api/**/*.ts) withmaxDuration: 60.Built-in cron in
vercel.jsonruns daily at0 0 * * *on/api/cron/revalidate.Register slash commands after deploy:
Operational Runbook
Initial setup
Configure environment variables.
Deploy to Vercel.
Register slash commands.
In Discord, run
/setup-gate ....Test end-to-end with
/verifyand callback payload.
Recommended production behavior
Keep
CHECK_MODE=simulateunless you intentionally need on-chain writes.Always protect callback and cron with secrets.
Use
/api/rpc/pingwhen checks time out or fail unexpectedly.
Troubleshooting
No roles are being assigned
Ensure callback is firing to
/api/verification/link.Confirm
discordUserId,walletPubkey, andguildIdare present.Verify mapping exists for guild (
/setup-gate).Check bot has role-management permissions and role hierarchy is correct.
/check says no linked wallet
/check says no linked walletCallback may not be configured.
User may have verified identity but wallet link is not in bot KV yet.
If needed, temporarily use
/link-walletfor testing.
Identity-related custom errors (6004, 6005, 6008, 6009)
6004, 6005, 6008, 6009)Run
/debug-identity gate_id.Add manual override with
/link-identity gate_id identity_pda [link_pda].Ensure verification DAO resolution is correct (
verification_dao_id/dao_id).
Cron not processing sync jobs
Confirm
GET /api/cron/revalidateis reachable.If
CRON_SECRETis set, ensure valid bearer token is provided.Check
MAX_SYNC_JOBS_PER_CRONand queue volume.
Example Callback Payload
Program IDs (Current Config)
Access:
GPASSzQQF1H8cdj5pUwFkeYEE4VdMQtCrYtUaMXvPz48Verification:
VrFyyRxPoyWxpABpBXU4YUCCF9p8giDSJUv2oXfDr5qReputation:
V1NE6WCWJPRiVFq5DtaN8p87M9DmmUd2zQuVbvLgQwX
Last updated