Skip to content

Commit 10f92c1

Browse files
committed
replace dall-e w/ gpt-image
1 parent e00224d commit 10f92c1

15 files changed

Lines changed: 405 additions & 227 deletions

README.md

Lines changed: 47 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
# DecryptGPT
22

3-
DecryptGPT is an advanced Discord bot developed by Decrypt, utilizing the `discord.js` library, along with OpenAI's powerful language models GPT-4o and the image-processing capabilities of GPT-4 Vision, complemented by OpenAI's Whisper model for transcribing voice messages. This bot offers a comprehensive AI experience within Discord channels, capable of engaging in text conversations, responding to voice inputs, analyzing visual content, processing documents (pdf, csv...), and seamlessly switching between different GPT models using slash commands. Whether for advanced medical revisions, casual interactions, or exploring the capabilities of AI, DecryptGPT is designed to enrich the Discord chat experience.
3+
DecryptGPT is an advanced Discord bot developed by Decrypt, utilizing the `discord.js` library, along with OpenAI's powerful language models GPT-4o and the image-processing capabilities of GPT-4 Vision and GPT-Image-1, complemented by OpenAI's Whisper model for transcribing voice messages. This bot offers a comprehensive AI experience within Discord channels, capable of engaging in text conversations, responding to voice inputs, analyzing visual content, processing documents, generating and editing images, and seamlessly switching between different GPT models using slash commands. Whether for advanced medical revisions, casual interactions, or exploring the capabilities of AI, DecryptGPT is designed to enrich the Discord chat experience.
44

55
## Features
66

77
- **Multiple GPT Modes**: Choose between GPT-4o or GPT-4 Vision for diverse interactions.
88
- **Voice Message Understanding**: DecryptGPT can transcribe voice messages and respond to them, making interaction more seamless.
99
- **Image Recognition**: With GPT-4 Vision, the bot can interpret images sent in the chat, adding a new dimension to AI conversations.
10+
- **Image Generation and Editing**: Using GPT-Image-1, the bot can:
11+
- **Generate** completely new images based on text prompts.
12+
- **Edit** existing uploaded images according to a provided text instruction.
1013
- **Document Processing**: The bot can analyze and extract text from various file formats:
1114
- PDF documents
1215
- Text files (.txt)
@@ -15,6 +18,16 @@ DecryptGPT is an advanced Discord bot developed by Decrypt, utilizing the `disco
1518
- **Customizable Configuration**: Tailor the bot's behavior through the `config.js` file, including setting the AI name, choosing the default GPT model, and more.
1619
- **Detailed Logging**: Enable detailed logging for debugging and monitoring interactions.
1720

21+
## Slash Commands
22+
23+
DecryptGPT supports several slash commands to interact with the AI:
24+
25+
- `/chat` — Start a conversation with the selected GPT model.
26+
- `/generate` — Generate a new image from a text prompt using **GPT-Image-1**.
27+
- `/edit` — Upload an image and provide a prompt to modify it using **GPT-Image-1**.
28+
29+
Console logs are included at every major step to ensure visibility on operations (e.g., request sent, response received, errors).
30+
1831
## Configuration
1932

2033
Before running DecryptGPT, some configurations are required:
@@ -24,62 +37,60 @@ Before running DecryptGPT, some configurations are required:
2437
```bash
2538
API_KEY=your_openai_api_key
2639
TOKEN=your_discord_bot_token
27-
```
40+
CLIENT_ID=your_discord_app_client_id
2841

29-
Replace `your_openai_api_key` and `your_discord_bot_token` with your respective OpenAI API key and Discord bot token.
42+
Replace your_openai_api_key and your_discord_bot_token with your respective OpenAI API key and Discord bot token.
43+
• channels.mjs: Edit channels.mjs to include the IDs of the Discord channels where the bot is allowed to operate. Channel IDs can be obtained by enabling Developer Mode in Discord and right-clicking on the channel to copy its ID.
44+
• config.js: Customize the bot’s settings in config.js.
3045

31-
- **channels.mjs**: Edit `channels.mjs` to include the IDs of the Discord channels where the bot is allowed to operate. Channel IDs can be obtained by enabling Developer Mode in Discord and right-clicking on the channel to copy its ID.
46+
Installation
3247

33-
- **config.js**: Customize the bot's settings in `config.js`.
48+
1. Clone the repository:
3449

35-
## Installation
50+
git clone <https://github.com/decryptu/DecryptGPT.git>
51+
52+
2. Navigate to the project directory:
3653

37-
1. Clone the repository:
54+
cd DecryptGPT
3855

39-
```bash
40-
git clone https://github.com/decryptu/DecryptGPT.git
41-
```
56+
3. Install dependencies:
4257

43-
2. Navigate to the project directory:
58+
npm install
4459

45-
```bash
46-
cd DecryptGPT
47-
```
60+
4. Install additional packages for document processing:
4861

49-
3. Install dependencies:
62+
npm install pdf.js-extract xlsx
5063

51-
```bash
52-
npm install
53-
```
64+
Running the Bot
65+
• To run the bot:
5466

55-
4. Install additional packages for document processing:
67+
npm start
5668

57-
```bash
58-
npm install pdf.js-extract xlsx
59-
```
69+
• For development with hot reloads:
6070

61-
## Running the Bot
71+
npm run dev
6272

63-
- To run the bot, use:
73+
Example Usage
74+
• Generate an image:
6475

65-
```bash
66-
npm start
67-
```
76+
/image prompt: "A futuristic city floating above the clouds"
6877

69-
- For development, with hot reloads, use:
78+
The bot will reply with an original AI-generated image.
7079

71-
```bash
72-
npm run dev
73-
```
80+
• Edit an uploaded image:
81+
82+
/image-edit image: [Upload your image] prompt: "Make the sky sunset-themed with flying cars"
83+
84+
The bot will modify the uploaded image according to the prompt.
7485

75-
## Contributing
86+
Contributing
7687

77-
Contributions to DecryptGPT are welcome! Please feel free to submit pull requests, create issues, or suggest new features.
88+
Contributions to DecryptGPT are welcome! Feel free to submit pull requests, create issues, or suggest new features.
7889

79-
## License
90+
License
8091

81-
This project is licensed under the [ISC License](LICENSE).
92+
This project is licensed under the ISC License.
8293

83-
---
94+
8495

8596
Developed with ❤️ by Decrypt

channels.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const allowedChannels = [
2-
"1185568440392617984", // decrypt
2+
"1088435060170051714", // decrypt
33
"1097824934153170984", // idkzp
44
"1272543925286211606", // idksmp
55
];

commands/dalle.js

Lines changed: 0 additions & 45 deletions
This file was deleted.

commands/image-edit.js

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
import { EmbedBuilder, AttachmentBuilder } from "discord.js";
2+
import axios from "axios";
3+
import { toFile } from "openai";
4+
5+
async function imageEdit(interaction, client) {
6+
// Immediately defer the reply to avoid timeout issues
7+
await interaction.deferReply();
8+
9+
try {
10+
// Log the interaction for debugging
11+
console.log("Image edit command received:", {
12+
user: interaction.user.tag,
13+
options: interaction.options.data
14+
});
15+
16+
const description = interaction.options.getString("description");
17+
const imageAttachment = interaction.options.getAttachment("image");
18+
19+
// Validate inputs after deferring to ensure we can respond properly
20+
if (!description) {
21+
return await interaction.editReply({
22+
content: "Please provide an image description."
23+
});
24+
}
25+
26+
if (!imageAttachment) {
27+
return await interaction.editReply({
28+
content: "Please provide a valid image attachment."
29+
});
30+
}
31+
32+
// Log the attachment details
33+
console.log("Attachment details:", {
34+
name: imageAttachment.name,
35+
contentType: imageAttachment.contentType,
36+
size: imageAttachment.size,
37+
url: imageAttachment.url
38+
});
39+
40+
if (!imageAttachment.contentType?.startsWith("image/")) {
41+
return await interaction.editReply({
42+
content: "The provided attachment is not an image. Please upload a PNG, JPEG, or WebP image."
43+
});
44+
}
45+
46+
// Download the image from Discord
47+
console.log("Downloading image from Discord...");
48+
const response = await axios.get(imageAttachment.url, { responseType: 'arraybuffer' });
49+
const imageBuffer = Buffer.from(response.data);
50+
console.log(`Image downloaded, size: ${imageBuffer.length} bytes`);
51+
52+
// Convert to proper format for OpenAI
53+
console.log("Converting image for OpenAI...");
54+
const imageFile = await toFile(imageBuffer, imageAttachment.name || "image.png", {
55+
type: imageAttachment.contentType
56+
});
57+
console.log("Image converted successfully");
58+
59+
// Call the edit endpoint
60+
console.log("Calling OpenAI edit API with prompt:", description);
61+
const result = await client.openai.images.edit({
62+
model: "gpt-image-1",
63+
image: imageFile,
64+
prompt: description,
65+
});
66+
67+
console.log("OpenAI API response received:", result);
68+
69+
if (!result?.data?.[0]?.b64_json) {
70+
throw new Error("No image data returned from API");
71+
}
72+
73+
// Convert base64 to buffer for Discord attachment
74+
const outputBuffer = Buffer.from(result.data[0].b64_json, "base64");
75+
const attachment = new AttachmentBuilder(outputBuffer, { name: "edited-image.png" });
76+
77+
const embed = new EmbedBuilder()
78+
.setTitle("Image edited successfully")
79+
.setDescription(`Prompt: ${description}`)
80+
.setImage("attachment://edited-image.png")
81+
.setTimestamp();
82+
83+
await interaction.editReply({
84+
content: null,
85+
embeds: [embed],
86+
files: [attachment]
87+
});
88+
89+
console.log("Successfully sent edited image response");
90+
} catch (error) {
91+
console.error("Error in imageEdit function:", error);
92+
93+
// Check for specific API errors
94+
const errorMessage = error.response?.data?.error?.message || error.message || "Unknown error";
95+
console.error("Detailed error:", errorMessage);
96+
97+
// Always use editReply since we deferred at the beginning
98+
await interaction.editReply({
99+
content: `Failed to edit the image. Error: ${errorMessage}`,
100+
embeds: [],
101+
files: []
102+
});
103+
}
104+
}
105+
106+
export default imageEdit;

commands/image-gpt.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import { EmbedBuilder, AttachmentBuilder, MessageFlags } from "discord.js";
2+
3+
async function imageGpt(interaction, client) {
4+
const description = interaction.options.getString("description");
5+
if (!description) {
6+
await interaction.reply({
7+
content: "Please provide an image description.",
8+
flags: MessageFlags.Ephemeral
9+
});
10+
return;
11+
}
12+
13+
try {
14+
// Acknowledge the interaction immediately to prevent timeouts
15+
await interaction.deferReply();
16+
17+
const imageBase64 = await client.createGptImage(description);
18+
19+
if (!imageBase64) {
20+
throw new Error("No image data returned");
21+
}
22+
23+
// Convert base64 to buffer for Discord attachment
24+
const buffer = Buffer.from(imageBase64, "base64");
25+
const attachment = new AttachmentBuilder(buffer, { name: "generated-image.png" });
26+
27+
const embed = new EmbedBuilder()
28+
.setTitle("Votre image")
29+
.setImage("attachment://generated-image.png");
30+
31+
await interaction.editReply({
32+
embeds: [embed],
33+
files: [attachment]
34+
});
35+
} catch (error) {
36+
console.error("Error in imageGpt function:", error);
37+
38+
// Check if the interaction has already been replied to
39+
if (interaction.deferred || interaction.replied) {
40+
await interaction.editReply({
41+
content: "Échec de la génération d'une image. Veuillez réessayer ultérieurement.",
42+
files: []
43+
});
44+
} else {
45+
await interaction.reply({
46+
content: "Échec de la génération d'une image. Veuillez réessayer ultérieurement.",
47+
flags: MessageFlags.Ephemeral
48+
});
49+
}
50+
}
51+
}
52+
53+
export default imageGpt;

0 commit comments

Comments
 (0)