client.channels.cache.get(channelid) returning undefined

Attempting to send a message to channels using the channel id. However, client.channels.cache.get(channelid) keeps returning undefined and client.channels.fetch(channelid).send(message) results in the following error:
TypeError: client.channels.fetch(...).send() is not a function
TypeError: client.channels.fetch(...).send() is not a function
. Any advice?
9 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
florence
florence4mo ago
where are you trying to do this? in index.js? just saying client.(the rest) won't work as you need to specify the guild you can use interaction.guild.channels.cache.get(id) if you want to get it where you have access to a CommandInteraction in a guild just doing client.channels doesn't work because you're not specifying a server
InfernalHarmony
InfernalHarmony4mo ago
I am not doing it as a return of an interaction. It is a timed event.
florence
florence4mo ago
can you send the full code then? not just the line oh uh
InfernalHarmony
InfernalHarmony4mo ago
Nvm. Got it to respond this time.
florence
florence4mo ago
not the whole file alrighty
InfernalHarmony
InfernalHarmony4mo ago
client.channels.fetch("" + data.channelid).then(channel => channel.send('<@' + User + '>, no opponent responded...')).catch(console.error);
client.channels.fetch("" + data.channelid).then(channel => channel.send('<@' + User + '>, no opponent responded...')).catch(console.error);
florence
florence4mo ago
has the issue rearised
InfernalHarmony
InfernalHarmony4mo ago
No, it has not. This was the solution for me.