Search code examples
javascriptnode.jsdiscord.js

How can I find username by nickname?


                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.


Solution

  • 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