繁体   English   中英

DiscordJS v14 在嵌入中添加图像附件

[英]DiscordJS v14 Add Image Attachment in the embed

我正在尝试添加到我的机器人的嵌入描述以从我的计算机获取图像附件并上传它,但它不断给我 MessageAttachment 错误。 你能帮帮我吗? 谢谢!

const { SlashCommandBuilder, EmbedBuilder, Embed } = require('discord.js');

module.exports = {
    data: new SlashCommandBuilder()
        .setName('rockstar')
        .setDescription('Only people with a very high role can use it!'),
    async execute(interaction, client, discord) {
        const attachment = new discord.MessageAttachment('C:\Users\Desktop\discord', 'ticket.png');
        const embed = new EmbedBuilder()
        .setTitle(`Test`)
        .setDescription(`Test Description`)
        .setColor(`fdaf17`)
        .setTimestamp(Date.now())
        .setThumbnail('attachment://ticket.png')
        .setAuthor({
            url: `https://wwww.google.com/`,
            iconURL: interaction.user.displayAvatarURL(),
            name: interaction.user.tag
        })
        .setFooter({
            iconURL: client.user.displayAvatarURL(),
            text: client.user.tag
        })
        .addFields([
            {
                name: `Testing Name Field`,
                value: `Name Field Value`,
                inline: true
            },
            {
                name: `Testing Name Field 2`,
                value: `Name Field Value 2`,
                inline: true
            }
        ]);
        
        //await interaction.reply({
        //    embeds: [embed]
        //});

        message.channel.send({embeds: [embed], files: [attachment]});
    },
};

discord.js v14 中,我们有一种发送附件的新方法,而不是MessageAttachment 我们现在有了AttachmentBuilder ,但代码更改应该很容易。 只需从discord.js导入AttachmentBuilder ,然后代替:

const attachment = new MessageAttachment('C:\Users\Desktop\discord', 'ticket.png')

尝试这个:

const attachment = new AttachmentBuilder('C:\Users\Desktop\discord', { name: 'ticket.png' })

有关从 v13 升级到 v14 时的重大更改列表,您可以在此处 go => 从 v13 更新到 v14

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM