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
- 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!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
id might be wrong
try console logging channel and see what you get
how do i do that?
console.log(channel)
?oooh sorry
its returning undefined
well then either channel is not cached or id is wrong or bot doesn't have access
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!