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 toolkit10mo 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
florentine
florentine10mo 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
InfernalHarmonyOP10mo ago
I am not doing it as a return of an interaction. It is a timed event.
florentine
florentine10mo ago
can you send the full code then? not just the line oh uh
InfernalHarmony
InfernalHarmonyOP10mo ago
Nvm. Got it to respond this time.
florentine
florentine10mo ago
not the whole file alrighty
InfernalHarmony
InfernalHarmonyOP10mo 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);
florentine
florentine10mo ago
has the issue rearised
InfernalHarmony
InfernalHarmonyOP10mo ago
No, it has not. This was the solution for me.
Want results from more Discord servers?
Add your server