feat: add logging for say command (closes #166)

This commit is contained in:
Ryan Cao 2023-05-24 11:25:06 +08:00
parent 8117ed29ec
commit b11b564e2d
No known key found for this signature in database
3 changed files with 42 additions and 6 deletions

37
src/commands/say.ts Normal file
View file

@ -0,0 +1,37 @@
import {
CacheType,
ChatInputCommandInteraction,
EmbedBuilder,
} from 'discord.js';
export const sayCommand = async (
interaction: ChatInputCommandInteraction<CacheType>
) => {
if (!interaction.guild || !interaction.channel) return;
const content = interaction.options.getString('content', true);
await interaction.deferReply({ ephemeral: true });
const message = await interaction.channel.send(content);
await interaction.editReply('I said what you said!');
if (typeof process.env.SAY_LOGS_CHANNEL === 'string') {
const logsChannel = await interaction.guild.channels.fetch(
process.env.SAY_LOGS_CHANNEL
);
if (!logsChannel?.isTextBased()) return;
await logsChannel.send({
embeds: [
new EmbedBuilder()
.setTitle('Say command used')
.setDescription(content)
.setAuthor({
name: interaction.user.tag,
iconURL: interaction.user.avatarURL() ?? undefined,
})
.setURL(message.url),
],
});
}
};