Handle it gracefully when we can't get guild member info. Indicate if this was due to the member not existing on the guild or because the endpoint didn't give us enough data.

master
Miikka Virtanen 2017-02-15 01:26:17 +02:00
parent e7ed0e5a21
commit 7320f6bf9c
1 changed files with 2 additions and 14 deletions

View File

@ -126,20 +126,7 @@ Here's what their message contained:
const memberPromise = (mainGuild ? mainGuild.getRESTMember(msg.author.id) : Promise.resolve()); const memberPromise = (mainGuild ? mainGuild.getRESTMember(msg.author.id) : Promise.resolve());
threadInitDonePromise = memberPromise threadInitDonePromise = memberPromise
.then(member => { .catch(err => {
console.log('member', member);
if (! member) return null;
// If the member doesn't have user data on it, try fetching that manually
if (! member.user) return restBot.getRESTUser(member.id).then(user => {
member.user = user;
return member;
}, err => {
console.log(`Could not get user for member ${member.id}`);
console.log(String(err));
return member;
});
return member;
}, err => {
console.log(`Member ${msg.author.id} not found in main guild ${config.mainGuildId}`); console.log(`Member ${msg.author.id} not found in main guild ${config.mainGuildId}`);
console.error(String(err)); console.error(String(err));
}) })
@ -147,6 +134,7 @@ Here's what their message contained:
let mainGuildNickname = null; let mainGuildNickname = null;
if (member && member.nick) mainGuildNickname = member.nick; if (member && member.nick) mainGuildNickname = member.nick;
else if (member && member.user) mainGuildNickname = member.user.username; else if (member && member.user) mainGuildNickname = member.user.username;
else if (member == null) mainGuildNickname = 'NOT ON SERVER';
if (mainGuildNickname == null) mainGuildNickname = 'UNKNOWN'; if (mainGuildNickname == null) mainGuildNickname = 'UNKNOWN';