Tldr: Calling message.mentions on a user that is offline results in the returned collection being empty.
Code snippet:
const Discord = require('discord.js');
const bot = new Discord.Client();
bot.on('message', message => {
if (message.content.startsWith("!")) {
console.log(message.mentions.members);
}
});
bot.login(TOKEN_HERE);
Repro steps:
User is online, call command "!test @testuser" returns following https://pastebin.com/U4UcHdAp, this is expected behaviour.
However, if the user then goes offline by closing discord or just appearing offline, then the returned collection is simply
Collection [Map] {}
Further details:
Both are intended behavior.
mentions.members operates on cache, if you don't have the person in cache, they won't show up.
If it's intended behaviour then okay, there probably should be a note in the docs about it.
In my specific circumstance though, I need to check the permissions of the @'ed user through hasPermission, to do this I need a GuildMember which only message.mentions.members provides. I currently can't see a way around this.
Another user on the discord suggested this
"MessageMentions.users instead, which doesn't rely on cache. And u can use Guild.fetchMember(...) passing the User which will return a Promise that resolves into a GuildMember which u can call hasPermission on"
I'll close this issue, thanks for the response.
Most helpful comment
Another user on the discord suggested this
"MessageMentions.users instead, which doesn't rely on cache. And u can use Guild.fetchMember(...) passing the User which will return a Promise that resolves into a GuildMember which u can call hasPermission on"
I'll close this issue, thanks for the response.