🎨 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 {
|
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()
|
||||||
|
.setTimestamp(new Date())
|
||||||
|
.setAuthor({
|
||||||
|
name: "Member Left",
|
||||||
|
iconURL:
|
||||||
|
"https://img.icons8.com/color-glass/48/000000/user-male-circle.png",
|
||||||
|
})
|
||||||
|
.setFooter({
|
||||||
|
text: embedConfig.footerText,
|
||||||
|
iconURL: embedConfig.footerIcon,
|
||||||
|
});
|
||||||
|
|
||||||
|
channel
|
||||||
.send({
|
.send({
|
||||||
embeds: [
|
embeds: [
|
||||||
new MessageEmbed()
|
embed
|
||||||
.setColor(errorColor)
|
.setColor(embedConfig.errorColor)
|
||||||
.setAuthor({
|
.setDescription(`${member.user} - (${member.user.tag})`)
|
||||||
name: "Member Left",
|
.addFields([
|
||||||
iconURL: member.user.displayAvatarURL(),
|
{
|
||||||
})
|
name: "Account Age",
|
||||||
.setDescription(`${member.user} ${member.user.tag}`)
|
value: `${member.user.createdAt}`,
|
||||||
.setTimestamp()
|
},
|
||||||
.setFooter({
|
]),
|
||||||
text: footerText,
|
|
||||||
iconURL: footerIcon,
|
|
||||||
}),
|
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
.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})`
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Reference in a new issue