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 ;-;
18 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
𝑫𝒆𝒂𝒕𝒉
First of all, you can use the get method instead of find
const channel = client.channels.cache.get("915481280538370059"); // -> K | undefined
const channel = client.channels.cache.get("915481280538370059"); // -> K | undefined
Keep in mind that the channel can be undefined if it wasn't found, so you can wrap the send method inside of a conditional
if (channel) { // If channel exists
channel.send({ embeds: [embed] }); // Sends the message
}
if (channel) { // If channel exists
channel.send({ embeds: [embed] }); // Sends the message
}
𝒄𝒐𝒄𝒐𝒌𝒊𝒕𝒕𝒆𝒏
do u know for sure that the channel is a text based channel in a guild the bot is on?
jakub
jakub4mo ago
if (channel) { // If channel exists channel.send({ embeds: [embed] }); // Sends the message }
that's just
channel?.send({ embeds: [embed] }); // Sends the message
channel?.send({ embeds: [embed] }); // Sends the message
channel?.send({ embeds: [embed] }) ?? (() => {
// else logic
})();
channel?.send({ embeds: [embed] }) ?? (() => {
// else logic
})();
(don't)
peachii
peachiiOP4mo ago
correct, yes im trying to collect the channel id to send the message into that channel when i kick someone i tried get and it still doesnt work :/ i tried the 2nd method, the command works, user is kicked, but the message is not sent into that channel and i get no error it is, its my bot and its in my server. it is a text based chat (sorry for late replies)
horohousu
horohousu4mo ago
that means that the channel doesn't exist, try logging the channel object and see what you get
treble/luna
treble/luna4mo ago
do you have the Guilds intent
peachii
peachiiOP4mo ago
im very sorry can you explain ;-; yes i do
horohousu
horohousu4mo ago
the id might be the wrong one use console.log(channel) after getting the channel to see if it exists
peachii
peachiiOP4mo ago
it comes up as undefined when i use the id in discord it links the correct channel so the id definitely is correct
No description
horohousu
horohousu4mo ago
are you absolutely sure? when you right click and copy the channel id it is the correct one?
peachii
peachiiOP4mo ago
yes, i use <#id> and it works perfectly
horohousu
horohousu4mo ago
maybe try fetch instead of cache.get? i doubt it changes anything but i really don't know why the current one wouldn't work if everything is set correctly
peachii
peachiiOP4mo ago
hm, i get this error TypeError: client.channels.cache.fetch is not a function
No description
horohousu
horohousu4mo ago
don't do cache.fetch, just fetch so
client.channels.fetch('')
client.channels.fetch('')
actually, do
interaction.guild.channels.fetch('')
interaction.guild.channels.fetch('')
instead
peachii
peachiiOP4mo ago
i get
Invalid Form Body
channel_id[NUMBER_TYPE_COERCE]: Value "channel => channel.id === "915481280538370059"" is not snowflake.
Invalid Form Body
channel_id[NUMBER_TYPE_COERCE]: Value "channel => channel.id === "915481280538370059"" is not snowflake.
when i use this, i get Error: Expected token to be set for this request, but none was present which is weird because my token is correct and ive logged my bot in correctly
horohousu
horohousu4mo ago
usually only the interaction gets passed onto the command so you should always use interaction instead of client did you await it? also can you show me the code
peachii
peachiiOP4mo ago
that worked!! thank you!
Want results from more Discord servers?
Add your server