peachii
peachii
DIAdiscord.js - Imagine an app
Created by peachii on 8/3/2024 in #djs-questions
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
6 replies
DIAdiscord.js - Imagine an app
Created by peachii on 7/8/2024 in #djs-questions
TypeError: Cannot read properties of undefined (reading 'send')
i did find a few posts on this error but no amount of research or looking through documentation has fixed my issue. basically, im receiving this error when i try to send a message from my discord bot to a specific channel using client.channels.cashe.get problem code: const channel = client.channels.cache.find(channel => channel.id === "915481280538370059"); await interaction.reply({content: 'User kicked :peachcord_checkmark:', ephemeral: true}); await channel.send({embeds: [embed]}) interaction.guild.members.kick(user); the problem is said to be with this line: await channel.send({embeds: [embed]}) the previous code is not necessary as its just my slash command builder and the issue is with the method im trying to use to send this message, but if its needed i can provide. if possible i would greatly appreciate some help ;-;
33 replies