简体   繁体   English

如何让 discord.js 机器人检测附件

[英]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留言#附件

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.

相关问题 如何使 Discord.js 机器人获取频道上的最后一个附件 - How to make Discord.js bot fetch last attachment on channel 如何在网站上制作 discord.js 机器人统计信息? - How I can make discord.js bot statistics on website? 如何让我的机器人在 Discord 频道 Discord.js 上设置慢速模式 - How can I make my bot set a slowmode on a Discord channel, Discord.js 如何让我的 Discord 机器人只忽略某些命令的设置前缀? (不和谐.js) - How can I make my Discord bot ignore the set prefix for certain commands only? (Discord.js) 如何在 discord.js bot 中创建提及头像命令? - How can make a Mention Avatar command in discord.js bot? 我将如何使用 Discord.js 制作一个“主持活动”的机器人? - How would I make a bot that "host events" with Discord.js? 用 discord.js 制作机器人,如何让我的机器人检测到某个短语? - Making a bot with discord.js, how to make my bot detect a certain phrase? discord.js:如何让机器人发送提及,但不在嵌入中? - discord.js: How can I make the bot send mention, but not in an embed? 如何发出重置命令来重新启动我的 discord.js 机器人? - How can i make a reset command to restart my discord.js bot? bot.on('messageCreate') discord.js 如何工作? 机器人不会检测到发送的消息,试图制作一个 discord 聊天机器人 - how dose the bot.on('messageCreate') discord.js work? the bot wont detect a sent message, trying to make a discord chat bot
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM