diff --git a/.env.example b/.env.example index a010304..27aec5b 100644 --- a/.env.example +++ b/.env.example @@ -1,2 +1,4 @@ DISCORD_TOKEN= -DISCORD_APP= \ No newline at end of file +DISCORD_APP= + +SAY_LOGS_CHANNEL= diff --git a/src/commands/say.ts b/src/commands/say.ts new file mode 100644 index 0000000..96e0979 --- /dev/null +++ b/src/commands/say.ts @@ -0,0 +1,37 @@ +import { + CacheType, + ChatInputCommandInteraction, + EmbedBuilder, +} from 'discord.js'; + +export const sayCommand = async ( + interaction: ChatInputCommandInteraction +) => { + 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), + ], + }); + } +}; diff --git a/src/index.ts b/src/index.ts index 88aec77..11001ba 100644 --- a/src/index.ts +++ b/src/index.ts @@ -19,6 +19,7 @@ import { modrinthCommand } from './commands/modrinth'; import { tagsCommand } from './commands/tags'; import { jokeCommand } from './commands/joke'; import { roryCommand } from './commands/rory'; +import { sayCommand } from './commands/say'; import random from 'just-random'; import { green, bold, yellow, cyan } from 'kleur/colors'; @@ -114,11 +115,7 @@ client.on('interactionCreate', async (interaction) => { } else if (commandName === 'modrinth') { await modrinthCommand(interaction); } else if (commandName === 'say') { - if (!interaction.channel) return; - - await interaction.deferReply({ ephemeral: true }); - await interaction.channel.send(interaction.options.getString('content')!); - await interaction.editReply('I said what you said!'); + await sayCommand(interaction); } else if (commandName === 'tag') { await tagsCommand(interaction); } else if (commandName === 'joke') {