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 }],
});
});
},
};
4 Replies
d.js toolkit
d.js toolkit13mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button! - Marked as resolved by OP
Noel
NoelOP13mo ago
please ping to respond
kin.ts
kin.ts13mo ago
you are not using AttachmentBuilder (you just import it) and since you have the image url, you can put it directly into the files array
await interaction.channel.send({ content: '...', files: [image.data[0].url] });
await interaction.channel.send({ content: '...', files: [image.data[0].url] });
Noel
NoelOP13mo ago
but you know how you can upload images to discord in messages and they dont send as downloads? how can i do that? or is that not possible... oh ok i fixed it with embeds ima mark as solved
Want results from more Discord servers?
Add your server