简体   繁体   English

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

[英]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.我正在使用 discord.js v13。

I've got the following code but img is not an image URL:我有以下代码,但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] });
});

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. awaitMessages返回消息集合。 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() .当您正确设置过滤器时,收集的消息将被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;消息有一个attachments属性,是消息中attachments的集合,所以图片将是集合中的第一项; collected.first().attachments.first() . collected.first().attachments.first() To grab the URL you can use either its url property:要获取 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.

相关问题 通过图 API 将照片提交给 facebook 后,如何获取照片 ID? - How can I obtain photo id after the photo has been submitted to facebook via graph API? 如何清理和清理用户提交的 url 以在 java 中重新显示? - how can I clean and sanitize a url submitted by a user for redisplay in java? 如何沙箱不受信任的用户提交的JavaScript内容? - How can I sandbox untrusted user-submitted JavaScript content? 如何修改用户提交的带有Chrome扩展程序的搜索输入中的查询? - How can I modify the query from a user submitted search input with a Chrome extension? 如果在提交后对内容进行了更改,我如何制作一个系统来通知用户? - How can I make a system to notify a user if changes have been made to content after it was submitted? 如何在Trivia游戏中收集用户的正确选择? - How can I collect the user's correct choice in my Trivia game? 当用户点击时,我如何收集x / y以及可能已被点击的任何链接? - When a user clicks, how can I collect the x/y as well as any link that may have been clicked? 如何使用 nodejs 对电子邮件进行身份验证? 我收到一封关于用户提交的电子邮件的电子邮件,然后我点击我端的一个链接来验证这封电子邮件 - How can I authenticate an email using nodejs? I get an email for user submitted email, then I click a link on my end to verify this email 尽管刷新浏览器,我怎样才能使同一用户不能两次喜欢照片? - How can I make it so that the same user cannot like a photo twice despite refreshing browser? 如何记录用户已使用JavaScript提交给表单的信息 - How do I log information a user has submitted to a form in JavaScript
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM