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 toolkit16mo 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
TheOceanCookieOP16mo 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
Preetham Hegade16mo ago
id might be wrong try console logging channel and see what you get
TheOceanCookie
TheOceanCookieOP16mo ago
how do i do that?
Preetham Hegade
Preetham Hegade16mo ago
console.log(channel) ?
TheOceanCookie
TheOceanCookieOP16mo ago
oooh sorry its returning undefined
Preetham Hegade
Preetham Hegade16mo ago
well then either channel is not cached or id is wrong or bot doesn't have access
TheOceanCookie
TheOceanCookieOP16mo 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!
Want results from more Discord servers?
Add your server