【问题标题】:DIscord.js putting an attachment in an embed's thumbnail doesn't show upDIScord.js 将附件放入嵌入的缩略图中不显示
【发布时间】:2021-06-15 23:05:00
【问题描述】:

我正在使用 discord.js,我正在尝试在嵌入的缩略图中显示本地图像,但它根本不显示,并且缩略图为空且未发送任何错误

const embed = new Discord.MessageEmbed()
        .setAuthor(`${user.tag}\'s profile (${user.id})`, user.avatarURL())
        .addField(`Skin`, `${skin2}`)
        .addField(`Total Coins`, `${coinicon} ${coins}`)
        .addField(`Inventory Items (${amount})`, `${items}`)
        .setThumbnail('attachment://red.png')
        .setTimestamp()
        .setColor('#00ffff')
        .setFooter(message.member.user.tag, message.author.avatarURL());
        message.channel.send(embed)

“red.png”是这样存储的

我也尝试将代码更改为

.setThumbnail('attachment://assets//colors//red.png')

但它也不起作用,有什么帮助吗?

【问题讨论】:

标签: node.js discord.js


【解决方案1】:

为了设置attachment://red.png,你实际上需要先附加它。
为此,请使用本地路径 + 附件名称(将在 attachment:// 中使用)创建一个附件:

const attachment = new Discord.MessageAttachment(
    "./path/to/red.png", // <- local image path
    "red.png"            // <- name for "attachment://"
);

然后使用附加它

.attachFiles(attachment)

在您的代码中:

const attachment = new Discord.MessageAttachment("./path/to/red.png", "red.png");

const embed = new Discord.MessageEmbed()
    .attachFiles(attachment) // <- add attachment
    .setAuthor(`${user.tag}\'s profile (${user.id})`, user.avatarURL())
    .addField(`Skin`, `${skin2}`)
    .addField(`Total Coins`, `${coinicon} ${coins}`)
    .addField(`Inventory Items (${amount})`, `${items}`)
    .setThumbnail('attachment://red.png')
    .setTimestamp()
    .setColor('#00ffff')
    .setFooter(message.member.user.tag, message.author.avatarURL());

message.channel.send(embed);

【讨论】:

    【解决方案2】:

    当您在帖子中使用第一个代码时,请尝试将 message.channel.send 更改为:

    message.channel.send({
        embed,
        files: [{
            attachment: '../../assets/colors/red.png',
            name: 'red.png'
        }]
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-12-06
      • 2020-05-26
      • 2023-03-29
      • 1970-01-01
      • 2020-12-09
      • 1970-01-01
      • 2017-04-25
      • 1970-01-01
      相关资源
      最近更新 更多