From de0fc48ba8b1dc97e80e586d59f57c69aca6de34 Mon Sep 17 00:00:00 2001 From: smyalygames Date: Fri, 17 Feb 2023 01:52:49 +0000 Subject: [PATCH] fix(arabot): fix problem for member not in server --- src/commands/mod/restriction/restrict.ts | 13 ++++++++++--- src/commands/mod/restriction/unrestrict.ts | 3 ++- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/commands/mod/restriction/restrict.ts b/src/commands/mod/restriction/restrict.ts index 065be95..0306161 100644 --- a/src/commands/mod/restriction/restrict.ts +++ b/src/commands/mod/restriction/restrict.ts @@ -58,6 +58,12 @@ export async function restrictRun( success: false, }; + let user = guild.client.users.cache.get(userId); + + if (user === undefined) { + user = await guild.client.users.fetch(userId) as User; + } + // Gets mod's GuildMember const mod = guild.members.cache.get(modId); @@ -79,7 +85,8 @@ export async function restrictRun( let member = guild.members.cache.get(userId); if (member === undefined) { - member = await guild.members.fetch(userId); + member = await guild.members.fetch(userId) + .catch(() => undefined); } const restrictRoles = IDs.roles.restrictions.restricted; @@ -239,14 +246,14 @@ export async function restrictRun( const message = new EmbedBuilder() .setColor('#FF6700') - .setAuthor({ name: `Restricted ${member.user.tag}`, iconURL: `${member.user.avatarURL()}` }) + .setAuthor({ name: `Restricted ${user.tag}`, iconURL: `${user.avatarURL()}` }) .addFields( { name: 'User', value: `${member}`, inline: true }, { name: 'Moderator', value: `${mod}`, inline: true }, { name: 'Reason', value: reason }, ) .setTimestamp() - .setFooter({ text: `ID: ${member.id}` }); + .setFooter({ text: `ID: ${userId}` }); await logChannel.send({ embeds: [message] }); diff --git a/src/commands/mod/restriction/unrestrict.ts b/src/commands/mod/restriction/unrestrict.ts index eeb3496..48656f0 100644 --- a/src/commands/mod/restriction/unrestrict.ts +++ b/src/commands/mod/restriction/unrestrict.ts @@ -139,7 +139,8 @@ export class UnRestrictCommand extends Command { let member = guild.members.cache.get(userId); if (member === undefined) { - member = await guild.members.fetch(userId); + member = await guild.members.fetch(userId) + .catch(() => undefined); } if (member === undefined) {