TypeError: Cannot read properties of undefined (reading 'send')

with settings.channel being a channel ID
const channel = client.channels.cache.get(settings.channel)
channel.send("e")
const channel = client.channels.cache.get(settings.channel)
channel.send("e")
25 Replies
d.js toolkit
d.js toolkit6mo 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! - Marked as resolved by OP
d.js docs
d.js docs6mo ago
- 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)
duck
duck6mo ago
(more so the first and last bullets assuming you have the Guilds intent)
Pigeon
PigeonOP6mo ago
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
duck
duck6mo ago
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?
Pigeon
PigeonOP6mo ago
when loggin channel.constructor.name i get TypeError: Cannot read properties of undefined (reading 'constructor') lol
duck
duck6mo ago
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?
Pigeon
PigeonOP6mo ago
it was from both at least thats what i think
duck
duck6mo ago
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
Pigeon
PigeonOP6mo ago
my node.js should be fine because what i am making wasnt a discord bot at the beginning and it worked perfectly
duck
duck6mo ago
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')
Pigeon
PigeonOP6mo ago
by logging channel it logs
undefined
undefined
duck
duck6mo ago
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)
Pigeon
PigeonOP6mo ago
these are my intents
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
],
});
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
],
});
its store in a json file
"channel":"here is the id"
"channel":"here is the id"
which should work if i am not mistaken
duck
duck6mo ago
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?
Pigeon
PigeonOP6mo ago
ye i checked the id when i log settings.channel it logs the channel id its a text channel
duck
duck6mo ago
then 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 provided
Pigeon
PigeonOP6mo ago
the code should execute if it crashes right?
duck
duck6mo ago
not sure what you're asking if the process crashes, no further code should be executing
Pigeon
PigeonOP6mo ago
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 code
duck
duck6mo ago
that is not what that error means it is reading send from undefined meaning channel is undefined again, you should triple check the id
Pigeon
PigeonOP6mo ago
i 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
duck
duck6mo ago
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
Pigeon
PigeonOP6mo ago
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
duck
duck6mo ago
no worries, glad you got there in the end
Want results from more Discord servers?
Add your server