Home > Software design >  How can I find username by nickname?
How can I find username by nickname?

Time:09-26

                for (let index = 0; index < 5; index  ) {
                    const kisi = interaction.guild.members.cache.find(m => m.nickname === oyuncu[index]);
                    console.log(kisi.user);
                }

When you use the code in this way, it only finds the username of 1 person.

CodePudding user response:

Only getting one user is because there are not more than a few members in the cache. Above your for loop, add

await guild.members.fetch()

When you add that line all the guild members will be in the cache and your code should work

Note that if you dont have the GuildMembers intent it will take a long time and after that time has passed an error will occur, saying that the members didnt arrive in time

CodePudding user response:

                    for (let index = 0; index < 5; index  )
                {
                    if (oyuncu[index])
                    {
                        const rol = guild.members.cache.find(role => role.nickname === oyuncu[index]);
                        if (rol)
                        {
                            console.log(rol)
                        }
                    }
                }

I tried a code like this but it still didn't work and only my username is visible

CodePudding user response:

                        interaction.guild.members.fetch();
                for (let index = 0; index < 5; index  )
                {
                    const rol = interaction.guild.members.cache.find(role => role.nickname === "Mre_Test");
                    if (rol)
                    {
                        console.log(rol.nickname);
                    }
                }

I understand what you mean, but still the same problem persists.

  • Related