繁体   English   中英

如何收集用户提交的照片?

[英]How can I collect a photo submitted by a user?

如何收集用户提交的照片并在嵌入中发送? 我正在使用 discord.js v13。

我有以下代码,但img不是图像 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] });
});

这是您可以尝试将图像定义为

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

让我知道这是否适合您...

awaitMessages返回消息集合。 即使它是一条消息,它仍然在一个集合中。 当您正确设置过滤器时,收集的消息将被collected.first()

消息有一个attachments属性,是消息中attachments的集合,所以图片将是集合中的第一项; collected.first().attachments.first() 要获取 URL,您可以使用其url属性:

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;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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