【问题标题】:How to log the attachment sent by the user in discord.js?如何在 discord.js 中记录用户发送的附件?
【发布时间】:2021-07-05 13:21:31
【问题描述】:

我一直在尝试编写一个 Discord 机器人,该机器人将用户发送的附件记录到嵌入中。我设法记录了附件的 URL,但它没有显示实际图像。有没有办法将用户发送的图像记录到嵌入中?任何帮助都将不胜感激。

An example

我当时的代码:

const attachments = message.attachments.size ? message.attachments.map(attachment => attachment.proxyURL) : null

let embed = new Discord.MessageEmbed()
.setAuthor(message.author.username, message.author.displayAvatarURL({ dynamic:true }))
.addField('Content', message.content)
.addField('Channel', message.channel)
.setTimestamp()
.setColor('RANDOM')

if(message.attachments.size > 0) embed.addField('Image', attachments)

【问题讨论】:

  • 字段中不能有图像。请改用.addImage()
  • .addImage() 不是函数。如果您在谈论.setImage(),我已经尝试过了,但它给我的只是DiscordAPIError: Invalid Form Body embed.image.url: Could not interpret "the attachment link here" as string.的错误

标签: discord discord.js


【解决方案1】:

检查MessageEmbed#setImage 方法。 (你也有MessageEmbed#setThumbnail

if(message.attachments.size > 0) embed.setImage(message.attachments.first().url)

【讨论】:

    猜你喜欢
    • 2021-12-03
    • 2021-05-17
    • 2021-10-17
    • 1970-01-01
    • 1970-01-01
    • 2021-03-26
    • 1970-01-01
    • 2021-03-27
    • 1970-01-01
    相关资源
    最近更新 更多