@valuya/discord-bot
v0.2.0-beta.1
Published
Discord adapter for payment-gated bots with Valuya Guard.
Downloads
90
Readme
@valuya/discord-bot
Discord adapter for payment-gated bots with Valuya Guard.
What it does
For slash commands or message commands, the adapter provides a predictable gate flow:
- Check entitlement
- If inactive, create checkout session
- Return a UX-ready payment prompt payload (
message,button, follow-up hint) - User pays and retries command
Install
npm i @valuya/discord-botQuick start
import { createDiscordGuard } from "@valuya/discord-bot"
const guard = createDiscordGuard({
base: process.env.VALUYA_BASE!,
tenantToken: process.env.VALUYA_TENANT_TOKEN!,
defaultPlan: "standard",
defaultResource: "discord:bot:premium",
})
const decision = await guard.gate({ user: { id: interaction.user.id } })
if (decision.active) {
// execute premium command
} else {
// show payment button using decision.prompt.button.url
}UX recommendations
- Keep payment prompts ephemeral for slash commands.
- Always include one-click
Pay Nowbutton. - Provide
/statuscommand to reduce support friction. - Cache recent pending sessions per user to avoid duplicate checkout creation.
Subject strategy
Default subject is:
{ "type": "discord", "id": "<discord_user_id>" }Override subjectType if your backend uses a different mapping.
