🎨 better audit log file for guildMemberRemove

This commit is contained in:
Axel Olausson Holtenäs 2022-05-30 18:26:00 +02:00
parent 2a81675c17
commit 1c722629dc
No known key found for this signature in database
GPG key ID: 7BF6826B76382CBA

View file

@ -7,49 +7,57 @@ import getEmbedConfig from "../../helpers/getEmbedConfig";
export default { export default {
execute: async (member: GuildMember) => { execute: async (member: GuildMember) => {
const { footerText, footerIcon, errorColor } = await getEmbedConfig( const { client, guild } = member;
member.guild
);
const guildData = await guildSchema.findOne({ guildId: member.guild.id }); const guildData = await guildSchema.findOne({ guildId: member.guild.id });
if (!guildData) {
const { client } = member; throw new Error("Could not find guild");
}
if (guildData === null) return;
if (guildData.audits.status !== true) return; if (guildData.audits.status !== true) return;
if (!guildData.audits.channelId) return; if (!guildData.audits.channelId) {
throw new Error("Channel not found");
}
const channel = client.channels.cache.get(`${guildData.audits.channelId}`); const embedConfig = await getEmbedConfig(guild);
if (channel === null) return; const channel = client.channels.cache.get(guildData.audits.channelId);
if (channel?.type !== "GUILD_TEXT") {
throw new Error("Channel must be a text channel");
}
(channel as TextChannel) const embed = new MessageEmbed()
.send({ .setTimestamp(new Date())
embeds: [
new MessageEmbed()
.setColor(errorColor)
.setAuthor({ .setAuthor({
name: "Member Left", name: "Member Left",
iconURL: member.user.displayAvatarURL(), iconURL:
"https://img.icons8.com/color-glass/48/000000/user-male-circle.png",
}) })
.setDescription(`${member.user} ${member.user.tag}`)
.setTimestamp()
.setFooter({ .setFooter({
text: footerText, text: embedConfig.footerText,
iconURL: footerIcon, iconURL: embedConfig.footerIcon,
}), });
channel
.send({
embeds: [
embed
.setColor(embedConfig.errorColor)
.setDescription(`${member.user} - (${member.user.tag})`)
.addFields([
{
name: "Account Age",
value: `${member.user.createdAt}`,
},
]),
], ],
}) })
.then(async () => { .then(async () => {
logger.info( logger.debug(
`Audit log sent for event guildMemberRemove in guild ${member.guild.name} (${member.guild.id})` `Audit log sent for event guildMemberRemove in guild ${member.guild.name} (${member.guild.id})`
); );
}) })
.catch(async () => { .catch(async () => {
logger.error( throw new Error("Audit log failed to send");
`Audit log failed to send for event guildMemberRemove in guild ${member.guild.name} (${member.guild.id})`
);
}); });
}, },
}; };