Discord.js: message.member returning null, was working previously for years

Created on 27 Oct 2020  路  3Comments  路  Source: discordjs/discord.js

After a working bot for more than 2 years, message.member is now returning null. Not sure why, here is my code:

if(!message.member.roles.has(adminRole.id)) { return message.reply("You're not an admin, sorry!"); }

getting an error of : " cannot find roles of null "

looked online and solutions were that I need to fetch guild member first?

so would the solution be:

guild.members.fetch()
.then(code here)
?

question (please use Discord instead)

All 3 comments

how are you getting the message? I assume this is not in a message event?

As of today, Discord requires you to have the GUILD_MEMBERS and GUILD_PRESENCES intents specified to get guild members with the initial payload. In v11, Message#member is set as a property instead of a getter, so the message author won't be in the guild's member cache yet. Please update to v12.

just update to v12, as v11 isn't supported anymore and it should work in v12.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ghost picture ghost  路  3Comments

tiritto picture tiritto  路  3Comments

xCuzImPro picture xCuzImPro  路  3Comments

Blumlaut picture Blumlaut  路  3Comments

ghost picture ghost  路  3Comments