xyter/src/plugins/events/interactionCreate/audits.ts

65 lines
1.9 KiB
TypeScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import logger from "../../../logger";
import { Interaction, MessageEmbed, TextChannel } from "discord.js";
import guildSchema from "../../../models/guild";
import getEmbedConfig from "../../../helpers/getEmbedConfig";
export default {
execute: async (interaction: Interaction) => {
if (interaction === null) return;
if (interaction.guild === null) return;
const { footerText, footerIcon, successColor } = await getEmbedConfig(
interaction.guild
);
const guildData = await guildSchema.findOne({
guildId: interaction.guild.id,
});
const { client } = interaction;
if (guildData === null) return;
if (guildData.audits.status !== true) return;
if (!guildData.audits.channelId) return;
const channel = client.channels.cache.get(`${guildData.audits.channelId}`);
if (channel === null) return;
(channel as TextChannel)
.send({
embeds: [
new MessageEmbed()
.setColor(successColor)
.setDescription(
`
**Interaction created by** ${interaction.user.username} **in** ${interaction.channel}
**Interaction ID**: ${interaction.id}
**Type**: ${interaction.type}
**User ID**: ${interaction.user.id}
`
)
.setThumbnail(interaction.user.displayAvatarURL())
.setTimestamp()
.setFooter({
text: footerText,
iconURL: footerIcon,
}),
],
})
.then(async () => {
logger.debug(
`Audit log sent for event interactionCreate in guild ${interaction?.guild?.name} (${interaction?.guild?.id})`
);
})
.catch(async () => {
logger.error(
`Audit log failed to send for event interactionCreate in guild ${interaction?.guild?.name} (${interaction?.guild?.id})`
);
});
},
};