简体   繁体   中英

How can I collect a photo submitted by a user?

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] });
});

Here's what you can try defining image as

let image = collected.attachments.first() ? message.attachments.first().proxyURL : null

Let me know if this works for you...

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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM