Reputation: 69
I am trying to add to my bot's embed description to get an image attachment from my computer and upload it but it keep giving me errors of MessageAttachment. Can you please help me out? Thanks!
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]});
},
};
Upvotes: 1
Views: 20324
Reputation: 2337
In discord.js
v14, we have a new way of sending attachments instead of MessageAttachment
. We now have AttachmentBuilder
but the code change should be pretty easy. Just import AttachmentBuilder
from discord.js
and then instead of this:
const attachment = new MessageAttachment('C:\Users\Desktop\discord', 'ticket.png')
try this:
const attachment = new AttachmentBuilder('C:\Users\Desktop\discord', { name: 'ticket.png' })
For the list of breaking changes when upgrading from v13 to v14, you can go here => Updating from v13 to v14
Upvotes: 5