feat(arabot): add extra check if guild/user not in cache

This commit is contained in:
Anthony 2022-08-31 00:40:26 +01:00
parent 5a5afbfb02
commit 35de24399a

View File

@ -27,18 +27,24 @@ export class VerifyUnblock extends ScheduledTask {
public async run(payload: { userId: string, guildId: string }) { public async run(payload: { userId: string, guildId: string }) {
// Get the guild where the user is in // Get the guild where the user is in
const guild = this.container.client.guilds.cache.get(payload.guildId); let guild = this.container.client.guilds.cache.get(payload.guildId);
if (guild === undefined) {
guild = await this.container.client.guilds.fetch(payload.guildId);
if (guild === undefined) { if (guild === undefined) {
console.error('verifyUnblock: Guild not found!'); console.error('verifyUnblock: Guild not found!');
return; return;
} }
}
// Find GuildMember for the user // Find GuildMember for the user
const user = guild.members.cache.get(payload.userId); let user = guild.members.cache.get(payload.userId);
if (user === undefined) {
user = await guild.members.fetch(payload.userId);
if (user === undefined) { if (user === undefined) {
console.error('verifyUnblock: GuildMember not found!'); console.error('verifyUnblock: GuildMember not found!');
return; return;
} }
}
// Remove the 'verify block' role // Remove the 'verify block' role
await user.roles.remove(IDs.roles.verifyBlock); await user.roles.remove(IDs.roles.verifyBlock);