Discord bot displays correct username on PC but shows @invalid-user on mobile

I’m in the process of developing a Discord bot for a friend’s server, and I’ve encountered a puzzling issue. Take a look at this section of my code:

client.on('message', message => {
    if(message.content.startsWith('${prefix}kick')){
        if(message.member.hasPermission('KICK_MEMBERS', 'BAN_MEMBERS')){
            let member = message.mentions.members.first();

The command prefix I’m using is e$. When I execute this kick command, the bot returns:

@member has been kicked.

On my PC, I can see the username of the mentioned member correctly, but when I view it on my phone, it shows:

@invalid-user has been kicked.

I’m really puzzled by this inconsistency. The command functions well on both devices but the output varies significantly. Has anyone else faced a similar problem? What might be the reason for this discrepancy between the desktop and mobile versions of Discord?

yeah, this prob happens due to caching on mobile. since mobile doesn’t keep user info like desktop, it shows @invalid-user. u can fix it by using member.user.username, that way it fetches the right name straight from the server.

This issue arises from the different ways in which Discord’s desktop and mobile clients manage user data caching. The mobile app imposes stricter cache limits and doesn’t retain user information locally like the desktop version. So, when your bot triggers a mention, it can access the username from its cache on the desktop, while the mobile app may not have that user’s information stored. I’ve encountered a similar situation with my own bots. Your code itself is functioning properly on both devices; it’s simply that mobile displays @invalid-user when it can’t immediately resolve the username. To achieve consistent username display across platforms, consider directly fetching the user object and using its username property instead of relying on mentions. This approach ensures that you’re accessing user data directly rather than depending on client-side caching.

Had this exact problem building a moderation bot last year. Discord’s mobile client handles user data differently than desktop, especially with cached info. When your bot sends a message with a user mention, desktop can resolve the username from its local cache, but mobile often can’t. Instead of relying on mentions in your response message, store the username in a variable before processing the kick. Something like let kickedUser = member.user.username; then use that variable in your response instead of the mention. You’re sending the actual username string rather than a mention that needs client resolution. The inconsistency is just cosmetic - the actual kick works fine on both platforms.