Principle:A616567126 GPT WEB JAVA Discord Interaction API
| Knowledge Sources | |
|---|---|
| Domains | API_Integration, Bot_Development |
| Last Updated | 2026-10-13 00:00 GMT |
Overview
Technique that submits slash-command interactions to Discord's REST API by constructing JSON payloads from parameterized templates and authenticating with a user token.
Description
Discord's interaction API allows bots to trigger slash commands (imagine, upscale, variation, describe, blend) by sending POST requests to Discord's interaction endpoint. Each interaction requires a JSON payload with guild_id, channel_id, session_id, nonce, and command-specific options.
This repository uses parameterized JSON templates (stored as resource files like imagine.json, upscale.json) with placeholder substitution ($guild_id, $channel_id, $nonce, etc.) to construct the interaction payloads. The DiscordServiceImpl sends these via RestTemplate with the Discord user token as authentication.
Usage
Use this principle when:
- Programmatically triggering Discord slash commands
- Integrating with Discord's interaction system from a Java backend
- Using template-based payload construction for multiple command types
Theoretical Basis
Template-Based Interaction:
# Abstract algorithm (NOT real implementation)
def send_interaction(template_name, prompt, nonce, account):
template = load_resource(f"api-params/{template_name}.json")
payload = template
.replace("$guild_id", account.guild_id)
.replace("$channel_id", account.channel_id)
.replace("$session_id", SESSION_ID)
.replace("$nonce", nonce)
payload["data"]["options"][0]["value"] = prompt
response = POST(DISCORD_API_URL, payload, auth=account.token)
if response.status == 204:
return SUCCESS
else:
return FAILURE
Key Properties:
- Template substitution: Resource JSON files with $-prefixed placeholders
- HTTP 204 success: Discord returns No Content on successful interaction
- User token auth:
Authorization: account.userTokenheader - Per-account context: Each Discord account has its own guild_id, channel_id, and token
Practical Guide
The repository implements this in DiscordServiceImpl:
imagine(prompt, nonce)— loadsimagine.json, substitutes placeholders, sets prompt valueupscale(messageId, index, messageHash, messageFlags, nonce)— loadsupscale.json, substitutes $message_id, $index, $message_hashvariation(...),reroll(...),describe(...),blend(...)— similar template-based constructionupload(fileName, dataUrl)— uploads image to Discord for describe/blend via two-step process (request upload URL, then PUT file)- All requests use
RestTemplate.postForEntity()with auth header
Related Pages
Implemented By
- Implementation:A616567126_GPT_WEB_JAVA_DiscordServiceImpl
- Implementation:A616567126_GPT_WEB_JAVA_TaskServiceImpl
- Implementation:A616567126_GPT_WEB_JAVA_MjController
- Implementation:A616567126_GPT_WEB_JAVA_WxOutServiceImpl
- Implementation:A616567126_GPT_WEB_JAVA_DiscordHelper
- Implementation:A616567126_GPT_WEB_JAVA_DiscordMessageServiceImpl
- Implementation:A616567126_GPT_WEB_JAVA_ConvertUtils