Help with error: TypeError: (intermediate value).setName is not a function

I am getting this error when trying to execute a message delete command. The goal is to delete a message using the message id of a message, then to send the user whose message was deleted, the log. I receive this error when it comes to sending the log. Error:
TypeError: (intermediate value).setName is not a function
at Object.execute (C:\Users\sw896\Desktop\ggpawss\commands\utilities\deletemessage.js:27:14)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async Client.<anonymous> (C:\Users\sw896\Desktop\ggpawss\index.js:95:3)
TypeError: (intermediate value).setName is not a function
at Object.execute (C:\Users\sw896\Desktop\ggpawss\commands\utilities\deletemessage.js:27:14)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async Client.<anonymous> (C:\Users\sw896\Desktop\ggpawss\index.js:95:3)
Code:
const { EmbedBuilder, SlashCommandBuilder} = require('discord.js');

module.exports = {
data: new SlashCommandBuilder()
.setName('deletemessage')
.setDescription('Deletes a message with the specified message ID and informs the user.')
.addStringOption(option =>
option.setName('messageid')
.setDescription('The ID of the message to delete')
.setRequired(true))
.addStringOption(option =>
option.setName('reason')
.setDescription('The reason for deleting the message')
.setRequired(true)),

async execute(interaction) {
const messageId = interaction.options.getString('messageid');
const channel = interaction.channel;

const message = await channel.messages.fetch(messageId);
const user = message.author;

await message.delete();
await interaction.reply({ content: 'Message deleted successfully!', ephemeral: true });

const embed = new EmbedBuilder()
.setName('Message deleted in peachcord')
.setDescription(`Message content: ${message.content} \nMessage ID: ${messageId}\n Reason: ${reason} \nAction carried out by: Moderator`)
.setColor(`#ffc7fd`)
.setTimestamp()

await user.send({ embeds: [embed] });
},
};
const { EmbedBuilder, SlashCommandBuilder} = require('discord.js');

module.exports = {
data: new SlashCommandBuilder()
.setName('deletemessage')
.setDescription('Deletes a message with the specified message ID and informs the user.')
.addStringOption(option =>
option.setName('messageid')
.setDescription('The ID of the message to delete')
.setRequired(true))
.addStringOption(option =>
option.setName('reason')
.setDescription('The reason for deleting the message')
.setRequired(true)),

async execute(interaction) {
const messageId = interaction.options.getString('messageid');
const channel = interaction.channel;

const message = await channel.messages.fetch(messageId);
const user = message.author;

await message.delete();
await interaction.reply({ content: 'Message deleted successfully!', ephemeral: true });

const embed = new EmbedBuilder()
.setName('Message deleted in peachcord')
.setDescription(`Message content: ${message.content} \nMessage ID: ${messageId}\n Reason: ${reason} \nAction carried out by: Moderator`)
.setColor(`#ffc7fd`)
.setTimestamp()

await user.send({ embeds: [embed] });
},
};
The problem code is in my embed builder:
const embed = new EmbedBuilder()
.setName('Message deleted in peachcord')
.setDescription(`Message content: ${message.content} \nMessage ID: ${messageId}\n Reason: ${reason} \nAction carried out by: Moderator`)
.setColor(`#ffc7fd`)
.setTimestamp()

const embed = new EmbedBuilder()
.setName('Message deleted in peachcord')
.setDescription(`Message content: ${message.content} \nMessage ID: ${messageId}\n Reason: ${reason} \nAction carried out by: Moderator`)
.setColor(`#ffc7fd`)
.setTimestamp()

I don't understand why I'm receiving this error as I've defined the embed builder at the beginning of the file? So the .setName function shouldnt be sending an error. I would love some help ;-; Thank you
3 Replies
d.js toolkit
d.js toolkit4mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button! - Marked as resolved by OP
treble/luna
treble/luna4mo ago
Its setTitle() for embed builders
peachii
peachiiOP4mo ago
oh my god i cant believe that flew past my head 😭 its been a long day thank you
Want results from more Discord servers?
Add your server