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?
ye i checked the id
when i log
settings.channel
it logs the channel id
its a text channelthen there really isn't a ton more to check
you do have the
Guilds
intent, so guild channels should be cached if your Client
is ready
therefore the only things that could possibly be an issue are the id being invalid or this code not actually executing when your Client
is ready
therefore on the assumption this code is still in an event listener, you should triple check the id
I am unable to help any further with just the info providedthe code should execute if it crashes right?
not sure what you're asking
if the process crashes, no further code should be executing
TypeError: Cannot read properties of undefined (reading 'send')
i think it is channel.send that is the problem
but it should work seeing that some people had it work using the same codethat is not what that error means
it is reading
send
from undefined
meaning channel
is undefined
again, you should triple check the idi changed the id to another channel, the id is the right one
it is channels from a server the bot is present to
i see the bot login on, it is online
well it'll still be hard to help any further with just the info provided
I can't verify that you've actually moved this code to an event listener, nor can I check the id for you
there really isn't anything further that could be an issue
oh i misunderstood
i only move the client.send to the event listener
yea now that const channel is in the event listener it works
mb sorry for the trouble
no worries, glad you got there in the end