feat: throw custom error for uncached Guild#me (#3271)

* handle cases where Guild#me is uncached

* fix id prop

* remove unnecessary checks

* space's requested changes
This commit is contained in:
izexi
2019-05-25 12:50:32 +01:00
committed by SpaceEEC
parent 34006cb51e
commit 3f1232ebf3
5 changed files with 21 additions and 13 deletions

View File

@@ -349,19 +349,20 @@ class GuildAuditLogsEntry {
guild_id: guild.id,
}));
} else if (targetType === Targets.INVITE) {
if (guild.me.permissions.has('MANAGE_GUILD')) {
const change = this.changes.find(c => c.key === 'code');
this.target = guild.fetchInvites()
.then(invites => {
this.target = guild.members.fetch(guild.client.user.id).then(me => {
if (me.permissions.has('MANAGE_GUILD')) {
const change = this.changes.find(c => c.key === 'code');
return guild.fetchInvites().then(invites => {
this.target = invites.find(i => i.code === (change.new || change.old));
return this.target;
});
} else {
this.target = this.changes.reduce((o, c) => {
o[c.key] = c.new || c.old;
return o;
}, {});
}
} else {
this.target = this.changes.reduce((o, c) => {
o[c.key] = c.new || c.old;
return o;
}, {});
return this.target;
}
});
} else if (targetType === Targets.MESSAGE) {
this.target = guild.client.users.get(data.target_id);
} else {