member.id is returning null for only one specific member
I've had a Discord bot running for over a year, no issue. The bot is running the latest version of discord.js: 14.21.0 on Node.js version 20.6.1.
A specific member that joined the server recently was having issues running some of the commands of my bot, so I looked into it. For THIS member (and no other members), anytime the code references a member id in a SlashCommand (interaction.member.id) the id attribute is null (TypeError: Cannot read properties of null (reading 'id')).
Does anyone know a reason why a specific member's id would be null? Like I mentioned, after a year of the bot running, this is the only individual where their member id comes back null.
10 Replies
the error
Cannot read properties of null (reading 'id') means it's reading id from null, not that the id is null
so if it is coming from interaction.member.id, sounds like interaction.member is null, so the interaction isn't coming from a guild in the first place
of course depending on what each use case is, you could always just use interaction.user.id which should always existHmmm... I'll look into user vs member in the docs, but still strange its the only individual where this is the case. I'll report back my findings and thanks for the help! 🙂
it could that the member user-installed the app or used the command in the bot's dm
They've tried commands using the mobile app and from a web browser on a PC.
From duck's reply and after reading the difference between user and member, I probably should be using user.id anyway... so I'll replace interaction.member.id uses to interaction.user.id references and have them retry.
I mean, the platform isn't what was at question
but if that solves your issue then great, it's a good solution if you need the id
Oh sorry... I guess I don't understand what you meant by "user-installed the app"
apps can be guild-installed, which is the regular old way, the app is invited as a member to a guild
or they can be user-installed, and the user can use the app's commands anywhere (depending on their context types), including guilds where the bot isn't present
but if the app isn't there as a member it doesn't get much info besides the options that were used
you can define which installations your app supports in the dev panel
Ah, I should have clarified. This is an app that authenticates to one specific guild (and I installed it as the admin).
So, it was guild-installed.
Yes. You were correct that the member was null (not the id).
After swapping out interaction.member.id with interaction.user.id in my commands that required a discord id, the commands now work for this individual. Still not sure why they are sole person having this issue, but I'm happy to have gotten a speedy answer to solve my problem.
Thank you so much!!
The thread owner has marked this issue as solved.