channel.send('content'); error ponying to .send

TypeError: Cannot read properties of undefined (reading 'send') i am trying to send a message to a channel without a user promting it to but it doesnt seem to work. heres the code i got from the discord.js guide: 'const channel = client.channels.cache.get('id'); channel.send('content');'
8 Replies
d.js toolkit
d.js toolkit2y 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!
TheOceanCookie
TheOceanCookieOP2y ago
file:///home/runner/bizbot/bot.js:28 channel.send('content'); ^ TypeError: Cannot read properties of undefined (reading 'send') at file:///home/runner/bizbot/bot.js:28:9
Preetham Hegade
id might be wrong try console logging channel and see what you get
TheOceanCookie
TheOceanCookieOP2y ago
how do i do that?
Preetham Hegade
console.log(channel) ?
TheOceanCookie
TheOceanCookieOP2y ago
oooh sorry its returning undefined
Preetham Hegade
well then either channel is not cached or id is wrong or bot doesn't have access
TheOceanCookie
TheOceanCookieOP2y ago
well the bot does have access and i checked the id and its right so i guess its not cached how to i cache it? (sorry i only started coding in javascript and discord.js yestarday) oh figured it out and the message was sent correctly, thank you!

Did you find this page helpful?