尝试根据昵称/显示名称获取成员.Discord.js BOT

时间:2023-02-10
本文介绍了尝试根据昵称/显示名称获取成员.Discord.js BOT的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我是否正在尝试为成员获取用户指定的昵称并获取该成员并获取有关该用户的其他信息.现在我已经确认用户发送的 ARGS[0] 是正确的,但我收到了对匹配用户的 NULL 响应.不知道我错过了什么.谢谢

Hi am i trying to take a user specified nickname for a member and fetch that members and get additional information about that user. Right now i have confirmed the ARGS[0] sent by the user is correct but i am getting a NULL response to the matched user. Not sure what i am missing. Thanks

这是我当前的代码.只是想立即让比赛正常进行.我还需要考虑这个人是否没有昵称来检查用户名.或者认为 displayname 属性会更好.谢谢

This is my current code. Just trying to get the match working right now. I also need to consider if the person doesnt have a nickname to check the username. Or think would displayname property be better. Thanks

if(command === "memberinfo") {
    let sentNickname = args[0];
    message.channel.send(`Sent Nickname: ${sentNickname}`);
    const discordserver = client.guilds.get(DragonTS); // Define server to get information from


    discordserver.fetchMembers() // Fetch guild members
        .then()  //.then(console.log)
        .catch(console.error);
}       
    let matchedMember = discordserver.members.find(m => m.nickname === sentNickname);
    message.channel.send(`Matched Member ${matchedMember}`);

推荐答案

您的代码的某些部分似乎没有执行.您需要将所有代码放入 .then():

Looks like some parts of your code aren't executed. You need to put all your code into the .then():

if(command === "memberinfo") {
    let sentNickname = args[0];
    message.channel.send(`Sent Nickname: ${sentNickname}`);
    const discordserver = client.guilds.get(DragonTS); // Define server to get information from


    discordserver.fetchMembers() // Fetch guild members
        .then((serverWithFetchedMembers) => {
            let matchedMember = serverWithFetchedMembers.members.find(m => m.nickname === sentNickname);
            message.channel.send(`Matched Member ${matchedMember}`);
        })  //.then(console.log)
        .catch(console.error);

}

它将等待 fetchMembers() 函数并在它之后执行您的代码!

It will wait for the fetchMembers() function and execute your code after it!

这篇关于尝试根据昵称/显示名称获取成员.Discord.js BOT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

上一篇:Discord.js 错误提供的角色不是角色、雪花或数组或 下一篇:如何让 selfbot 加入服务器?

相关文章

最新文章