Question
This Content is from Stack Overflow. Question asked by tanaallen
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:UsersDesktopdiscord', '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:
//});
message.channel.send({embeds:
, files: [attachment]});
},
};
Solution
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
Answered by Caladan
This Question and Answer are collected from stackoverflow and tested by JTuto community, is licensed under the terms of CC BY-SA 4.0.