0

I am trying to find a GuildMember by their nickname. Their nickname is set to their Roblox name when they join the server and I have set a webhook up to send a message in a channel containing their username and some other information, and it splits that message up so that the username is by itself. I am using a guild.members.fetch function with an await in front of it, but it keeps timing out and giving the error: Members didn't arrive in time.

Code

let msg = message.content.toLowerCase();

    if (message.channel.id === '795814242397585418' && message.author.bot && message.author.id != client.user.id) {
        //client.channels.cache.get('795814242397585418').send('Someone bought a product');
        let splitMsg = msg.split(' bought ');
        let customer = await message.guild.members.fetch(m => m.nickname === splitMsg[0]);
        customer.send('You bought ', splitMsg[2]);
    };

It is inside a client.on('message', async message => {}) function.

MrLlamaDev
  • 21
  • 5
  • Does [None of my discord.js guildmember events are emitting, my user caches are basically empty, and my functions are timing out?](https://stackoverflow.com/questions/64559390) help? – Jakye Jan 05 '21 at 07:10
  • @Jakye I have done that now, but, I am having trouble with using the customer variable now. When trying to log something from the customer I get an error: TypeError: Cannot read property of 'tag' of undefined or when trying to send the user a message: TypeError: customer.send is not a function. Idk what to do – MrLlamaDev Jan 05 '21 at 09:34

1 Answers1

0

there is a property on members called displayName which shows their nickname in that server. If they don't have a nickname in that server, it will just return their username. Be careful to only use this on members, not users:

let user = client.members.cache.find(member => member.displayName == "My Nickname");
Yankue
  • 388
  • 6
  • 14