Cannot read properties of undefined (reading `fetch`)
I'm trying to add a role to a newly joined user, after parsing their display name through an external API.
However, I get an error stating that I cannot read the properties of undefined (reading
fetch
).
const { Guild, GuildMember } = require('discord.js');
...
A quick note on GuildMember
: according to VSCode, it's value is unused. I do not get why.
Node version: v18.15.0
9 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 OPwhatever Guild is, its undefined
Or well, not undefined, but also not a proper guild instance
what did you define
roles
as
most likely you dont need to fetch the roles at allI was attempting to get a list of roles from the guild, and sort through them by using the numerical ID. (I'm porting the bot from JavaCord, which is the way it used to work).
Also, the
fetch(roles);
is most definetly a typo, as that should be role
, refering to the numerical ID.then that would already not work because you didn't provide a role id to the function to begin with
:skull:
and then you could just do
guildMember.roles.add(role)
Huh. That's a fair bit easier than expected.
I'll give that a shot, and mark the post as resolved if that fixes it.
Regardless, thank you for the help!
:reallyFckingCuteCatThumbsUp:
Yep, that seems to have worked.
I am missing an intent apparently, as the API throws a "Missing Access" error. But that's a separate issue.