Unable to send an embed

Hi, my code is practically the one that is included in the guide. I added a command which exports, during the execute phase an embed. When I try to post it into a specific channel from the index.js file there is an error I can't fix There is a document that has both the addAnime.js file and the index.js file along with the error I get
14 Replies
d.js toolkit
d.js toolkit3d 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
Retro
Retro3d ago
read the guide again. the execute function is there to use when the command runs. also module.exports cannot be used outside of global scope
paves
pavesOP3d ago
How can I get embed data from a command and send it to a specific channel using the index.js file?
Retro
Retro3d ago
you dont code the command in index.js the code should be in your execute file
paves
pavesOP3d ago
How can i send it to a specific channel from the execute file Found out that doesn't really work and tried into the index.js file
Retro
Retro3d ago
pass the client to the function
paves
pavesOP3d ago
now it works but cant gather the information to send
Retro
Retro3d ago
now you only have interaction
paves
pavesOP3d ago
how do i do that
Retro
Retro3d ago
pass client in there too i recommend you freshen up on your js basics #resources but tldr
command.execute(interaction, client)

// command file
execute(interaction, client) {
// your code in here
}
command.execute(interaction, client)

// command file
execute(interaction, client) {
// your code in here
}
again this is quite basic javascript you should freshen up
paves
pavesOP3d ago
Thanks TypeError: Cannot read properties of undefined (reading 'channels') at Object.execute (C:\Users\Andrea Pavesi\discord-bot\commands\utility\addAnime.js:46:20) at Client.<anonymous> (C:\Users\Andrea Pavesi\discord-bot\index.js:41:17) at Client.emit (node:events:518:28) at InteractionCreateAction.handle (C:\Users\Andrea Pavesi\discord-bot\node_modules\discord.js\src\client\actions\InteractionCreate.js:97:12) at module.exports [as INTERACTION_CREATE] (C:\Users\Andrea Pavesi\discord-bot\node_modules\discord.js\src\client\websocket\handlers\INTERACTION_CREATE.js:4:36) at WebSocketManager.handlePacket (C:\Users\Andrea Pavesi\discord-bot\node_modules\discord.js\src\client\websocket\WebSocketManager.js:348:31) at WebSocketManager.<anonymous> (C:\Users\Andrea Pavesi\discord-bot\node_modules\discord.js\src\client\websocket\WebSocketManager.js:232:12) at WebSocketManager.emit (C:\Users\Andrea Pavesi\discord-bot\node_modules@vladfrangu\async_event_emitter\dist\index.cjs:287:31) at WebSocketShard.<anonymous> (C:\Users\Andrea Pavesi\discord-bot\node_modules@discordjs\ws\dist\index.js:1190:51) at WebSocketShard.emit (C:\Users\Andrea Pavesi\discord-bot\node_modules@vladfrangu\async_event_emitter\dist\index.cjs:287:31)
async execute(interaction, client) {
const exampleEmbed = new EmbedBuilder()
.setColor("#" + (205).toString(16) + (92).toString(16) + (92).toString(16))
.setTitle(interaction.options.getString('nome'))
.setAuthor({
name: `Anime suggerito da ${interaction.user.username}`, // Use backticks for string interpolation
iconURL: 'https://cdn.discordapp.com/attachments/1354490500349956218/1354490770916380692/NuovoLogoSeratona.png?ex=67e96fd5&is=67e81e55&hm=befc54a682598d7473a3d470d14e15ada532b2188acbc7c327cf08675e2b9fb7&',
url: null // Set to null or a valid URL
})
.setDescription(interaction.options.getString('descrizione') + '\n**Genere**: ' + interaction.options.getString('genere') + '\n **Guardalo da:**\n> [' + interaction.options.getString('guardanome') + '](' + interaction.options.getString('guardalink') + ')')
.setThumbnail('https://cdn.discordapp.com/attachments/1354490500349956218/1354490770916380692/NuovoLogoSeratona.png?ex=67e96fd5&is=67e81e55&hm=befc54a682598d7473a3d470d14e15ada532b2188acbc7c327cf08675e2b9fb7&')
.setImage(interaction.options.getString('immagine'))
.setTimestamp()
.setFooter({ text: 'Bot by paves' });
client.channels.cache.get('1353095151848788179').send({embeds: [exampleEmbed]});
await interaction.reply({ content: 'Messaggio inviato in <#1353095151848788179>', ephemeral:true });
console.log(`Anime richiesto da ${interaction.user.username} inviato nel canale`);
}
async execute(interaction, client) {
const exampleEmbed = new EmbedBuilder()
.setColor("#" + (205).toString(16) + (92).toString(16) + (92).toString(16))
.setTitle(interaction.options.getString('nome'))
.setAuthor({
name: `Anime suggerito da ${interaction.user.username}`, // Use backticks for string interpolation
iconURL: 'https://cdn.discordapp.com/attachments/1354490500349956218/1354490770916380692/NuovoLogoSeratona.png?ex=67e96fd5&is=67e81e55&hm=befc54a682598d7473a3d470d14e15ada532b2188acbc7c327cf08675e2b9fb7&',
url: null // Set to null or a valid URL
})
.setDescription(interaction.options.getString('descrizione') + '\n**Genere**: ' + interaction.options.getString('genere') + '\n **Guardalo da:**\n> [' + interaction.options.getString('guardanome') + '](' + interaction.options.getString('guardalink') + ')')
.setThumbnail('https://cdn.discordapp.com/attachments/1354490500349956218/1354490770916380692/NuovoLogoSeratona.png?ex=67e96fd5&is=67e81e55&hm=befc54a682598d7473a3d470d14e15ada532b2188acbc7c327cf08675e2b9fb7&')
.setImage(interaction.options.getString('immagine'))
.setTimestamp()
.setFooter({ text: 'Bot by paves' });
client.channels.cache.get('1353095151848788179').send({embeds: [exampleEmbed]});
await interaction.reply({ content: 'Messaggio inviato in <#1353095151848788179>', ephemeral:true });
console.log(`Anime richiesto da ${interaction.user.username} inviato nel canale`);
}
d.js docs
d.js docs3d ago
tag suggestion for @paves: The order of function parameters must match between definition and function call.
function execute(client, interaction) { ... };
execute(interaction, client);
function execute(client, interaction) { ... };
execute(interaction, client);
- mismatch! you pass an interaction where the client is expected - mismatch! you pass the client where an interaction is expected
Retro
Retro3d ago
in your case, i dont think you pass the client in your main file
paves
pavesOP3d ago
thank you it works

Did you find this page helpful?