Implementation:A616567126 GPT WEB JAVA DiscordServiceImpl
| Knowledge Sources | |
|---|---|
| Domains | Discord_API, Bot_Development |
| Last Updated | 2026-10-13 00:00 GMT |
Overview
Concrete tool for calling Discord's REST interaction API to trigger Midjourney slash commands (imagine, upscale, variation, reroll, describe, blend) using parameterized JSON templates.
Description
The DiscordServiceImpl class implements the DiscordService interface. It constructs JSON payloads from resource template files (imagine.json, upscale.json, etc.) by substituting placeholders ($guild_id, $channel_id, $session_id, $nonce, $message_id, etc.) with account-specific values. Requests are sent via RestTemplate with the Discord user token as authentication.
HTTP 204 (No Content) from Discord indicates a successful interaction. Any other response is treated as an error with the response body as the message.
The upload() method handles two-step image upload: first requests an upload URL from Discord, then PUTs the file data. The sendImageMessage() method posts an image message to a Discord channel.
Usage
Import this service when you need to:
- Call Discord's interaction API for Midjourney commands
- Upload images to Discord for describe/blend tasks
- Understand the template-based payload construction
Code Reference
Source Location
- Repository: GPT-WEB-JAVA
- File: src/main/java/com/intelligent/bot/service/mj/impl/DiscordServiceImpl.java
Signature
public class DiscordServiceImpl implements DiscordService {
public DiscordServiceImpl(DiscordAccount account, RestTemplate restTemplate, Map<String, String> paramsMap);
public B<Void> imagine(String prompt, String nonce);
public B<Void> upscale(String messageId, int index, String messageHash, int messageFlags, String nonce);
public B<Void> variation(String messageId, int index, String messageHash, int messageFlags, String nonce);
public B<Void> reroll(String messageId, String messageHash, int messageFlags, String nonce);
public B<Void> describe(String finalFileName, String nonce);
public B<Void> blend(List<String> finalFileNames, BlendDimensions dimensions, String nonce);
public B<String> upload(String fileName, DataUrl dataUrl);
public B<String> sendImageMessage(String content, String finalFileName);
}
Import
import com.intelligent.bot.service.mj.impl.DiscordServiceImpl;
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| prompt | String | Yes (imagine) | English prompt text |
| nonce | String | Yes | Unique task nonce for event matching |
| messageId | String | Yes (upscale/variation) | Discord message ID of original task |
| messageHash | String | Yes (upscale/variation) | Discord message hash |
| finalFileName | String | Yes (describe) | Uploaded file name on Discord |
Outputs
| Name | Type | Description |
|---|---|---|
| imagine/upscale/etc returns | B<Void> | Success (HTTP 204) or error message |
| upload returns | B<String> | Discord upload filename for the uploaded file |
Usage Examples
Imagine Interaction
// Loads imagine.json template, substitutes placeholders:
// $guild_id → account.guildId
// $channel_id → account.channelId
// $session_id → MJ_SESSION_ID
// $nonce → task nonce
// Sets options[0].value = prompt
// POSTs to Discord API with account.userToken
// Returns B.okBuild() if HTTP 204
Image Upload
B<String> uploadResult = discordInstance.upload(taskFileName, dataUrl);
// 1. POST to Discord upload URL endpoint with file metadata
// 2. Get upload_url and upload_filename from response
// 3. PUT file bytes to upload_url
// 4. Return upload_filename for use in describe/blend