TypeError: Cannot read properties of undefined (reading 'send')
with settings.channel being a channel ID
25 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!
- ✅
Marked as resolved by OP- The provided id is incorrect (copy role ids from context menus, not message mentions)
- The client does not have this structure cached (try fetching instead)
- The client is not yet ready (move the code into any event listener callback)
(more so the first and last bullets assuming you have the
Guilds
intent)after moving it into an event listener i get this, i also get the same error by fetching instead of caching
TypeError: channel.send is not a function
the id is correct
that error suggests
channel
exists but is not a text based channel
putting aside fetching, what type of channel is it?
if you log channel.constructor.name
, what is it?
have you double checked that the id is actually for a text based channel?when loggin channel.constructor.name i get
TypeError: Cannot read properties of undefined (reading 'constructor')
lol
doesn't sound like
channel
exists then
are you sure you received channel.send is not a function
after moving this code to an event, or was it just from fetching?it was from both
at least thats what i think
well if you're genuinely getting both of these errors after having moved this code to an event, something is incredibly wrong with your installation of node.js
generally it's far more likely that you've simply made a small mistake
it'll be hard to give you any further info without confirming one way or the other
my node.js should be fine because what i am making wasnt a discord bot at the beginning
and it worked perfectly
my answer still has not changed
if
channel
is undefined
, you should not be receiving channel.send is not a function
if channel
is not undefined
, you should not be receiving Cannot read properties of undefined (reading 'constructor')
by logging channel it logs
then
channel
is undefined
, which suggests you were not receiving channel.send is not a function
from this code
I'd guess it was just from fetching in which case you weren't handling the promise properly
but again putting that aside (since you shouldn't need to fetch non-thread channels if you have the Guilds
intent), you'll probably want to double check that the id is valid and is stored as a string (not a number)these are my intents
its store in a json file
which should work if i am not mistaken
sure
have you double checked that the id is valid?
if you log
settings.channel
does the id actually log?
what type of channel is it?