[英]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.