feat: add logging for say command (closes #166)
This commit is contained in:
parent
8117ed29ec
commit
b11b564e2d
3 changed files with 42 additions and 6 deletions
|
@ -1,2 +1,4 @@
|
|||
DISCORD_TOKEN=
|
||||
DISCORD_APP=
|
||||
|
||||
SAY_LOGS_CHANNEL=
|
||||
|
|
37
src/commands/say.ts
Normal file
37
src/commands/say.ts
Normal 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),
|
||||
],
|
||||
});
|
||||
}
|
||||
};
|
|
@ -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') {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue