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 toolkit3mo 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 docs3mo 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
duck3mo ago
(more so the first and last bullets assuming you have the Guilds intent)
Pigeon
Pigeon3mo 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
duck3mo 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
Pigeon3mo ago
when loggin channel.constructor.name i get TypeError: Cannot read properties of undefined (reading 'constructor') lol
duck
duck3mo 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
Pigeon3mo ago
it was from both at least thats what i think
duck
duck3mo 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
Pigeon3mo ago
my node.js should be fine because what i am making wasnt a discord bot at the beginning and it worked perfectly
duck
duck3mo 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
Pigeon3mo ago
by logging channel it logs
undefined
undefined
duck
duck3mo 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
Pigeon3mo 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
duck3mo 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?
Want results from more Discord servers?
Add your server