How can I collect a photo submitted by a user and send it in an embed? I'm using discord.js v13.
I've got the following code but img is not an image URL:
interaction.reply({ content: 'Envia alguna imagen...' }).then(async () => {
const atch_filter = (m) => !!m.attachments || m.startsWith('https');
const collected = await interaction.channel.awaitMessages({
filter: atch_filter,
max: 1,
});
var img = collected.first().url;
const embed = new MessageEmbed()
.setTitle('Foto recibida')
.setImage(img)
.setColor('BLUE');
interaction.editReply({ content: 'Listo!', embeds: [embed] });
});
awaitMessages returns a collection of messages. Even if it's a single message it's still in a collection. As you set up your filter correctly, the collected message will be collected.first().
Messages have an attachments property, a collection of attachments in the message, so the image will be the first item in the collection; collected.first().attachments.first(). To grab the URL you can use either its url property:
const atch_filter = (m) => !!m.attachments || m.startsWith('https');
const collected = await interaction.channel.awaitMessages({
filter: atch_filter,
max: 1,
});
const img = collected.first().attachments.first().url;
Here's what you can try defining image as
let image = collected.attachments.first() ? message.attachments.first().proxyURL : null