fix(arabot): fixed issues with using GuildMember instead of User leading to undefined instances

This commit is contained in:
smyalygames 2023-02-18 03:08:38 +00:00
parent 62e3c698fb
commit ea58ecc261
2 changed files with 24 additions and 10 deletions

View File

@ -61,7 +61,11 @@ export async function restrictRun(
let user = guild.client.users.cache.get(userId);
if (user === undefined) {
user = await guild.client.users.fetch(userId) as User;
user = await guild.client.users.fetch(userId);
if (user === undefined) {
info.message = 'Error fetching user';
return info;
}
}
// Gets mod's GuildMember
@ -227,7 +231,7 @@ export async function restrictRun(
// Restrict the user on the database
await restrict(userId, modId, reason, section);
info.message = `Restricted ${member}`;
info.message = `Restricted ${user}`;
info.success = true;
// Log the ban
@ -239,7 +243,7 @@ export async function restrictRun(
.fetch(IDs.channels.logs.restricted) as TextChannel | undefined;
if (logChannel === undefined) {
container.logger.error('Restrict Error: Could not fetch log channel');
info.message = `Restricted ${member} but could not find the log channel. This has been logged to the database.`;
info.message = `Restricted ${user} but could not find the log channel. This has been logged to the database.`;
return info;
}
}
@ -248,7 +252,7 @@ export async function restrictRun(
.setColor('#FF6700')
.setAuthor({ name: `Restricted ${user.tag}`, iconURL: `${user.avatarURL()}` })
.addFields(
{ name: 'User', value: `${member}`, inline: true },
{ name: 'User', value: `${user}`, inline: true },
{ name: 'Moderator', value: `${mod}`, inline: true },
{ name: 'Reason', value: reason },
)

View File

@ -121,6 +121,16 @@ export class UnRestrictCommand extends Command {
success: false,
};
let user = guild.client.users.cache.get(userId);
if (user === undefined) {
user = await guild.client.users.fetch(userId);
if (user === undefined) {
info.message = 'Error fetching user';
return info;
}
}
// Gets mod's GuildMember
const mod = guild.members.cache.get(modId);
@ -157,7 +167,7 @@ export class UnRestrictCommand extends Command {
// Checks if the user is not restricted
if (!member.roles.cache.hasAny(...restrictRoles)) {
info.message = `${member} is not restricted!`;
info.message = `${user} is not restricted!`;
return info;
}
@ -219,24 +229,24 @@ export class UnRestrictCommand extends Command {
.fetch(IDs.channels.logs.restricted) as TextChannel | undefined;
if (logChannel === undefined) {
this.container.logger.error('Restrict Error: Could not fetch log channel');
info.message = `Unrestricted ${member} but could not find the log channel. This has been logged to the database.`;
info.message = `Unrestricted ${user} but could not find the log channel. This has been logged to the database.`;
return info;
}
}
const message = new EmbedBuilder()
.setColor('#28A745')
.setAuthor({ name: `Unrestricted ${member.user.tag}`, iconURL: `${member.user.avatarURL()}` })
.setAuthor({ name: `Unrestricted ${user.tag}`, iconURL: `${user.avatarURL()}` })
.addFields(
{ name: 'User', value: `${member}`, inline: true },
{ name: 'User', value: `${user}`, inline: true },
{ name: 'Moderator', value: `${mod}`, inline: true },
)
.setTimestamp()
.setFooter({ text: `ID: ${member.id}` });
.setFooter({ text: `ID: ${userId}` });
await logChannel.send({ embeds: [message] });
info.message = `Unrestricted ${member}`;
info.message = `Unrestricted ${user}`;
return info;
}
}