2023-05-28 14:08:51 +00:00
|
|
|
const { SlashCommandBuilder } = require('@discordjs/builders');
|
|
|
|
const fn = require('../functions.js');
|
2023-05-31 12:33:03 +00:00
|
|
|
const strings = require("../strings.json");
|
2023-05-28 14:08:51 +00:00
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
data: new SlashCommandBuilder()
|
|
|
|
.setName('dalle')
|
|
|
|
.setDescription('Generate an image with DALL-e')
|
|
|
|
.addStringOption(o =>
|
|
|
|
o.setName("prompt")
|
|
|
|
.setDescription("Prompt to send to DALL-e")
|
|
|
|
.setRequired(true)
|
2023-05-29 12:47:07 +00:00
|
|
|
)
|
|
|
|
.addStringOption(o =>
|
|
|
|
o.setName("size")
|
|
|
|
.setDescription("1024x1024, 512x512, 256x256")
|
|
|
|
.setRequired(false)
|
|
|
|
.addChoices(
|
|
|
|
{ name: "1024x1024 (2¢)", value: "1024x1024" },
|
|
|
|
{ name: "512x512 (1.8¢)", value: "512x512" },
|
|
|
|
{ name: "256x256 (1.6¢)", value: "256x256" }
|
|
|
|
)),
|
2023-05-28 14:08:51 +00:00
|
|
|
async execute(interaction) {
|
|
|
|
try {
|
|
|
|
await interaction.deferReply();
|
2023-06-15 23:07:16 +00:00
|
|
|
await interaction.editReply(fn.embeds.generatingResponse());
|
2023-05-28 14:08:51 +00:00
|
|
|
const userPrompt = interaction.options.getString("prompt");
|
2023-05-29 12:47:07 +00:00
|
|
|
const size = interaction.options.getString("size") ? interaction.options.getString("size") : "512x512";
|
|
|
|
|
|
|
|
const imageUrl = await fn.openAI.imagePrompt(userPrompt, size);
|
2023-05-31 12:07:12 +00:00
|
|
|
const dalleEmbed = fn.embeds.dalle(userPrompt, imageUrl, size);
|
2023-05-29 12:47:07 +00:00
|
|
|
await interaction.editReply(dalleEmbed);
|
2023-05-31 12:33:03 +00:00
|
|
|
fn.upload.openai(interaction.user.id, userPrompt, "dalle", 0, strings.costs.dalle[size]);
|
2023-05-28 14:08:51 +00:00
|
|
|
} catch (err) {
|
|
|
|
const errorId = fn.generateErrorId();
|
|
|
|
console.error(`${errorId}: ${err}`);
|
|
|
|
await interaction.editReply(`An error has occured. Error ID: ${errorId}\n${err}`);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
};
|