🎨 better audit log file for guildMemberRemove
This commit is contained in:
parent
2a81675c17
commit
1c722629dc
1 changed files with 36 additions and 28 deletions
|
@ -7,49 +7,57 @@ import getEmbedConfig from "../../helpers/getEmbedConfig";
|
|||
|
||||
export default {
|
||||
execute: async (member: GuildMember) => {
|
||||
const { footerText, footerIcon, errorColor } = await getEmbedConfig(
|
||||
member.guild
|
||||
);
|
||||
const { client, guild } = member;
|
||||
|
||||
const guildData = await guildSchema.findOne({ guildId: member.guild.id });
|
||||
|
||||
const { client } = member;
|
||||
|
||||
if (guildData === null) return;
|
||||
|
||||
if (!guildData) {
|
||||
throw new Error("Could not find guild");
|
||||
}
|
||||
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)
|
||||
.send({
|
||||
embeds: [
|
||||
new MessageEmbed()
|
||||
.setColor(errorColor)
|
||||
const embed = new MessageEmbed()
|
||||
.setTimestamp(new Date())
|
||||
.setAuthor({
|
||||
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({
|
||||
text: footerText,
|
||||
iconURL: footerIcon,
|
||||
}),
|
||||
text: embedConfig.footerText,
|
||||
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 () => {
|
||||
logger.info(
|
||||
logger.debug(
|
||||
`Audit log sent for event guildMemberRemove in guild ${member.guild.name} (${member.guild.id})`
|
||||
);
|
||||
})
|
||||
.catch(async () => {
|
||||
logger.error(
|
||||
`Audit log failed to send for event guildMemberRemove in guild ${member.guild.name} (${member.guild.id})`
|
||||
);
|
||||
throw new Error("Audit log failed to send");
|
||||
});
|
||||
},
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue