Discord Commands
Reference for the unified Discord command router and notify service.
Embed and Component Types
Source: src/data/discord-commands/discord-embed.types.ts
| Type | Description |
|---|---|
DiscordEmbed | Rich message embed (title, description, fields) |
DiscordButton | Button component (type 2) with custom_id or url |
DiscordStringSelect | Select menu (type 3) for options |
DiscordTextInput | Modal text input (type 4) |
DiscordModalData | Modal response (type 9) |
DISCORD_BUTTON_STYLE provides PRIMARY, SECONDARY, SUCCESS, DANGER, LINK.
Custom ID Constants
Source: src/data/discord-commands/discord-custom-id.constants.ts
Format: {prefix}:{action}:{params} (max 100 chars). Prefixes: order, address. Actions include add, step, use-address, address:confirm, address:new, address:edit, address:submit. Steps: products, shipping, payment, submit. Use buildCustomId() and parseCustomId() helpers.
Command Router
Source: src/data/discord-commands/discord-command-router.ts
Routes slash commands, message components (buttons, selects), and modal submits to order flow, product management, address management, notify, and help.
execute
| Aspect | Details |
|---|---|
| Input | { tenantId, guildId?, channelId?, discordUserId, commandName, rawOptions, memberRoleIds? } |
| Output | Promise<DiscordCommandResult> (content/embeds/components or modal) |
| Side effects | Delegates to order router, product repo, customer service, or notify service as appropriate. |
executeComponent
| Aspect | Details |
|---|---|
| Input | { tenantId, guildId?, channelId?, discordUserId, customId, values? } |
| Output | Promise<DiscordCommandResult> |
| Side effects | Handles order flow steps, address select, product add, payment, submit. |
executeModal
| Aspect | Details |
|---|---|
| Input | { tenantId, guildId?, channelId?, discordUserId, customId, components } |
| Output | Promise<DiscordCommandResult> |
| Side effects | Handles address add/edit and order shipping address form submission. |
DiscordNotifyService
Source: src/data/discord-commands/discord-notify.service.ts
send
| Aspect | Details |
|---|---|
| Input | ctx, { message, target: 'channel' | 'dm', channelId?, tenantId }, { botToken, getDiscordIdsForTenant } |
| Output | Promise<{ sent: number, failed: number, errors: string[] }> |
| Side effects | Sends messages via Discord REST API. Channel target posts to the given channel. DM target sends to each tenant customer with a Discord ID. |
Error Constants
Source: src/data/discord-commands/discord-commands.errors.ts
| Constant | Description |
|---|---|
NOTIFY_BOT_TOKEN_REQUIRED | DISCORD_BOT_TOKEN is required for notify delivery. |
NOTIFY_CHANNEL_REQUIRED | Channel ID is required for channel target. |
NOTIFY_DM_CREATE_FAILED | Failed to create DM channel. |
NOTIFY_SEND_FAILED | Failed to send message. |