Noel
Noel
DIAdiscord.js - Imagine an app
Created by Noel on 12/5/2023 in #djs-questions
images dont appear
when i put an attachment using AttachmentBuilder in to the files: []part of a message it appears in discord as something i have to download. im trying to embed it right into discord. code:
const { SlashCommandBuilder, AttachmentBuilder } = require("discord.js");
const { OpenAI } = require("openai");

const data = new SlashCommandBuilder()
.setName("imagine")
.setDescription("Uses AI to generate images!")
.addStringOption((option) =>
option
.setName("prompt")
.setDescription("Describe what you'd like to generate...")
.setRequired(true)
);

module.exports = {
data: data,
async execute(interaction) {
let generateMessage = await interaction.reply("Generating...");
const openai = new OpenAI();
await openai.images
.generate({
prompt: interaction.options.getString("prompt"),
})
.then(async (image) => {
await generateMessage.delete();
/*
await interaction.channel.send(
`${interaction.user}! We just finished generating your image! It can be viewed at the following link: ${image.data[0].url}`
);
*/
await interaction.channel.send({
content: `${interaction.user}! We just finished generating your image!`,
files: [{ attachment: image.data[0].url }],
});
});
},
};
const { SlashCommandBuilder, AttachmentBuilder } = require("discord.js");
const { OpenAI } = require("openai");

const data = new SlashCommandBuilder()
.setName("imagine")
.setDescription("Uses AI to generate images!")
.addStringOption((option) =>
option
.setName("prompt")
.setDescription("Describe what you'd like to generate...")
.setRequired(true)
);

module.exports = {
data: data,
async execute(interaction) {
let generateMessage = await interaction.reply("Generating...");
const openai = new OpenAI();
await openai.images
.generate({
prompt: interaction.options.getString("prompt"),
})
.then(async (image) => {
await generateMessage.delete();
/*
await interaction.channel.send(
`${interaction.user}! We just finished generating your image! It can be viewed at the following link: ${image.data[0].url}`
);
*/
await interaction.channel.send({
content: `${interaction.user}! We just finished generating your image!`,
files: [{ attachment: image.data[0].url }],
});
});
},
};
8 replies
DIAdiscord.js - Imagine an app
Created by Noel on 12/5/2023 in #djs-questions
how can i incorporate ai image generation?
i'd just like to know how to incorporate ai image generation into this. i want it to respond that it's generating the image once the user uses the command, and then i want to send the image once its done later
const { SlashCommandBuilder, AttachmentBuilder } = require("discord.js");
const { OpenAI } = require("openai");

const data = new SlashCommandBuilder()
.setName("imagine")
.setDescription("Uses AI to generate images!")
.addStringOption((option) =>
option
.setName("prompt")
.setDescription("Describe what you'd like to generate...")
.setRequired(true)
);

module.exports = {
data: data,
async execute(interaction) {
await interaction.reply("Generating...");
},
};
const { SlashCommandBuilder, AttachmentBuilder } = require("discord.js");
const { OpenAI } = require("openai");

const data = new SlashCommandBuilder()
.setName("imagine")
.setDescription("Uses AI to generate images!")
.addStringOption((option) =>
option
.setName("prompt")
.setDescription("Describe what you'd like to generate...")
.setRequired(true)
);

module.exports = {
data: data,
async execute(interaction) {
await interaction.reply("Generating...");
},
};
8 replies