Send Embed to Channel with ID

I would like to send my embed to a channel specified by ID. Unfortunately it doesn't work in my code.
const { EmbedBuilder, ButtonInteraction } = require("discord.js");

module.exports = {
name: "interactionCreate",
once: false,
/**
*
* @param {ButtonInteraction} interaction
* @param {*} client
*/
async execute(interaction, client) {
if(interaction.isButton()) {
if(interaction.customId == "einstempeln") {
const channel = client.channels.cache.get('1222955254174453945');
if (!channel) return console.log("Channel not found");

const embed = new EmbedBuilder()
.setColor(0x6AA84F)
.setTitle('Dienst-Eintragung')
.setDescription('Du hast dich erfolgreich in den Dienst eingetragen!')
.setTimestamp()
.setFooter({text: 'Benni Techniker'});

channel.send({embeds: [embed]});
}
}
}
}
const { EmbedBuilder, ButtonInteraction } = require("discord.js");

module.exports = {
name: "interactionCreate",
once: false,
/**
*
* @param {ButtonInteraction} interaction
* @param {*} client
*/
async execute(interaction, client) {
if(interaction.isButton()) {
if(interaction.customId == "einstempeln") {
const channel = client.channels.cache.get('1222955254174453945');
if (!channel) return console.log("Channel not found");

const embed = new EmbedBuilder()
.setColor(0x6AA84F)
.setTitle('Dienst-Eintragung')
.setDescription('Du hast dich erfolgreich in den Dienst eingetragen!')
.setTimestamp()
.setFooter({text: 'Benni Techniker'});

channel.send({embeds: [embed]});
}
}
}
}
14 Replies
d.js toolkit
d.js toolkit8mo 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
Unknown User
Unknown User8mo ago
Message Not Public
Sign In & Join Server To View
❄Moba Welt❄
❄Moba Welt❄OP8mo ago
The embed is not sent to the channel I specified when I press the button.
Unknown User
Unknown User8mo ago
Message Not Public
Sign In & Join Server To View
❄Moba Welt❄
❄Moba Welt❄OP8mo ago
Yeah, wait
No command matching undefined was found.
node:events:497
throw er; // Unhandled 'error' event
^

TypeError: Cannot read properties of undefined (reading 'channels')
at Object.execute (C:\Users\User\Desktop\BenniTechniker\events\button.js:14:40)
at Client.<anonymous> (C:\Users\User\Desktop\BenniTechniker\index.js:35:44)
at Client.emit (node:events:531:35)
at InteractionCreateAction.handle (C:\Users\User\Desktop\BenniTechniker\node_modules\discord.js\src\client\actions\InteractionCreate.js:97:12)
at module.exports [as INTERACTION_CREATE] (C:\Users\User\Desktop\BenniTechniker\node_modules\discord.js\src\client\websocket\handlers\INTERACTION_CREATE.js:4:36)
at WebSocketManager.handlePacket (C:\Users\User\Desktop\BenniTechniker\node_modules\discord.js\src\client\websocket\WebSocketManager.js:355:31)
at WebSocketManager.<anonymous> (C:\Users\User\Desktop\BenniTechniker\node_modules\discord.js\src\client\websocket\WebSocketManager.js:239:12)
at WebSocketManager.emit (C:\Users\User\Desktop\BenniTechniker\node_modules\@vladfrangu\async_event_emitter\dist\index.cjs:282:31)
at WebSocketShard.<anonymous> (C:\Users\User\Desktop\BenniTechniker\node_modules\@discordjs\ws\dist\index.js:1173:51)
at WebSocketShard.emit (C:\Users\User\Desktop\BenniTechniker\node_modules\@vladfrangu\async_event_emitter\dist\index.cjs:282:31)
Emitted 'error' event on Client instance at:
at emitUnhandledRejectionOrErr (node:events:402:10)
at process.processTicksAndRejections (node:internal/process/task_queues:84:21)
No command matching undefined was found.
node:events:497
throw er; // Unhandled 'error' event
^

TypeError: Cannot read properties of undefined (reading 'channels')
at Object.execute (C:\Users\User\Desktop\BenniTechniker\events\button.js:14:40)
at Client.<anonymous> (C:\Users\User\Desktop\BenniTechniker\index.js:35:44)
at Client.emit (node:events:531:35)
at InteractionCreateAction.handle (C:\Users\User\Desktop\BenniTechniker\node_modules\discord.js\src\client\actions\InteractionCreate.js:97:12)
at module.exports [as INTERACTION_CREATE] (C:\Users\User\Desktop\BenniTechniker\node_modules\discord.js\src\client\websocket\handlers\INTERACTION_CREATE.js:4:36)
at WebSocketManager.handlePacket (C:\Users\User\Desktop\BenniTechniker\node_modules\discord.js\src\client\websocket\WebSocketManager.js:355:31)
at WebSocketManager.<anonymous> (C:\Users\User\Desktop\BenniTechniker\node_modules\discord.js\src\client\websocket\WebSocketManager.js:239:12)
at WebSocketManager.emit (C:\Users\User\Desktop\BenniTechniker\node_modules\@vladfrangu\async_event_emitter\dist\index.cjs:282:31)
at WebSocketShard.<anonymous> (C:\Users\User\Desktop\BenniTechniker\node_modules\@discordjs\ws\dist\index.js:1173:51)
at WebSocketShard.emit (C:\Users\User\Desktop\BenniTechniker\node_modules\@vladfrangu\async_event_emitter\dist\index.cjs:282:31)
Emitted 'error' event on Client instance at:
at emitUnhandledRejectionOrErr (node:events:402:10)
at process.processTicksAndRejections (node:internal/process/task_queues:84:21)
Unknown User
Unknown User8mo ago
Message Not Public
Sign In & Join Server To View
❄Moba Welt❄
❄Moba Welt❄OP8mo ago
How can I use this?
Unknown User
Unknown User8mo ago
Message Not Public
Sign In & Join Server To View
❄Moba Welt❄
❄Moba Welt❄OP8mo ago
Ah oh
Unknown User
Unknown User8mo ago
Message Not Public
Sign In & Join Server To View
❄Moba Welt❄
❄Moba Welt❄OP8mo ago
Okay, thank you very much. Now it works. There is only this text in the console: No command matching undefined was found.
Unknown User
Unknown User8mo ago
Message Not Public
Sign In & Join Server To View
❄Moba Welt❄
❄Moba Welt❄OP8mo ago
👍 Where in the docs can I find this exactly?
d.js docs
d.js docs8mo ago
:guide: Creating Your Bot: Command handling read more
Want results from more Discord servers?
Add your server