嗨,我正在尝试为成员指定用户指定的昵称并获取该成员并获取有关该用户的其他信息。现在,我已经确认用户发送的ARGS [0]是正确的,但是我收到了对匹配用户的NULL响应。不知道我在想什么。谢谢
这是我当前的代码。只是想立即使比赛正常进行。我还需要考虑该人是否没有昵称来检查用户名。或者认为displayname属性会更好。谢谢
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}`);
答案 0 :(得分:0)
看起来您的代码的某些部分没有执行。您需要将所有代码放入.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()
函数并在其后执行代码!