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. 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. Knowing that we can now get the first message attachment and get its URL using the following code:
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);
}
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.