简体   繁体   中英

discord.js Role Manager not showing role

I wanted to have a check on whether a user has a role or not, with a simple

let author = message.author.id
let guild = await client.guilds.fetch("guild")
let member = await guild.members.fetch(author)

member.roles.cache.has("role")

However, sometimes it returns false even though I just gave that member a role. And it still returns true after I remove their role. It'll work again only after I reset the bot.

Is this a bug or do I need to cache the member as a whole again? If so, how would I go about doing this to make it quick?

Seems like a cache issue you're facing...

I've not really developed using discord api however reading their documentation I get the impression that you should be using either:

await guild.members.fetch({ user: author/id, force: true });

The force flag specifies not to use cache in the query - more here . Obviously with disabling cache, you might experience performance degradation.

Additionally, the documentation specifies message.member object which might be doing this already for you, saving you a query or two.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM