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:
Code:
The problem code is in my embed builder:
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
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