Discord.js: Calling message.mentions on offline user results in the returned collection being empty

Created on 7 Apr 2019  Â·  3Comments  Â·  Source: discordjs/discord.js

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:

  • discord.js version: 11.4.2
  • Node.js version: 10.5.0
  • Operating system: Windows 7
  • Priority this issue should have – please be realistic and elaborate if possible:
  • [ ] I have also tested the issue on latest master, commit hash:
question (please use Discord instead)

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.

All 3 comments

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ghost picture ghost  Â·  3Comments

LLamaFTL picture LLamaFTL  Â·  3Comments

Dmitry221060 picture Dmitry221060  Â·  3Comments

tom-barnes picture tom-barnes  Â·  3Comments

smchase picture smchase  Â·  3Comments