[英]How can I make discord.js bot detect an attachment
I'm trying to make my Discord bot invert an attachment with REST API but I don't know how to change "${message.author.avatarURL}" so it can detect the message attachment instead of the user's avatar.我正在尝试使我的 Discord 机器人使用 REST API 消息来反转附件,但我不知道如何更改“${message.author”的 userURL} 的附件。 What should I do?
我应该怎么办?
else if (message.content.toLowerCase() === 'invert'){
let link = `https://some-random-api.ml/canvas/invert/?avatar=${message.author.avatarURL({ format: 'png'})}`
let attachment = new MessageAttachment(link, 'invert.png');
message.channel.send(attachment);
}
message.attachments
is a message object property that returns an array of all attachment objects inside of a message. message.attachments
是一个消息 object 属性,它返回消息内所有附件对象的数组。 Knowing that we can now get the first message attachment and get its URL using the following code:知道我们现在可以使用以下代码获取第一个消息附件并获取其 URL:
else if (message.content.toLowerCase() === 'invert'){
const attachmentURL = message.attachments.first();
if (!attachmentURL) return message.reply('Please provide an image!');
let link = `https://some-random-api.ml/canvas/invert/?avatar=${attachmentURL.url}`
let attachment = new MessageAttachment(link, 'invert.png');
message.channel.send(attachment);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.