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..fd3af32 --- /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 (process.env.SAY_LOGS_CHANNEL) { + 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/constants.ts b/src/constants.ts index 3a88957..20c3586 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -24,6 +24,3 @@ export const COLORS = { yellow: 0xfde047, orange: 0xfb923c, } as { [key: string]: number }; - -/* CHANGEME */ -export const ALLOWED_ROLES = ['Alert', 'Events', 'Progress']; diff --git a/src/index.ts b/src/index.ts index 5a657e6..11001ba 100644 --- a/src/index.ts +++ b/src/index.ts @@ -4,6 +4,7 @@ import { Partials, OAuth2Scopes, InteractionType, + PermissionFlagsBits, } from 'discord.js'; import { reuploadCommands } from './_reupload'; @@ -18,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'; @@ -32,7 +34,7 @@ const client = new Client({ GatewayIntentBits.GuildMembers, GatewayIntentBits.GuildPresences, GatewayIntentBits.GuildMessageReactions, - GatewayIntentBits.GuildBans, + GatewayIntentBits.GuildModeration, ], partials: [Partials.Channel], }); @@ -45,21 +47,21 @@ client.once('ready', async () => { client.generateInvite({ scopes: [OAuth2Scopes.Bot], permissions: [ - 'AddReactions', - 'ViewChannel', - 'BanMembers', - 'KickMembers', - 'CreatePublicThreads', - 'CreatePrivateThreads', - 'EmbedLinks', - 'ManageChannels', - 'ManageRoles', - 'ModerateMembers', - 'MentionEveryone', - 'MuteMembers', - 'SendMessages', - 'SendMessagesInThreads', - 'ReadMessageHistory', + PermissionFlagsBits.AddReactions, + PermissionFlagsBits.ViewChannel, + PermissionFlagsBits.BanMembers, + PermissionFlagsBits.KickMembers, + PermissionFlagsBits.CreatePublicThreads, + PermissionFlagsBits.CreatePrivateThreads, + PermissionFlagsBits.EmbedLinks, + PermissionFlagsBits.ManageChannels, + PermissionFlagsBits.ManageRoles, + PermissionFlagsBits.ModerateMembers, + PermissionFlagsBits.MentionEveryone, + PermissionFlagsBits.MuteMembers, + PermissionFlagsBits.SendMessages, + PermissionFlagsBits.SendMessagesInThreads, + PermissionFlagsBits.ReadMessageHistory, ], }) ) @@ -98,22 +100,6 @@ client.once('ready', async () => { }); client.on('interactionCreate', async (interaction) => { - if (interaction.isButton() && interaction.customId === 'delete-message') { - const messageRef = interaction.message.reference?.messageId; - if (messageRef) { - const msg = await interaction.message.channel.messages.fetch(messageRef); - - if (interaction?.user === msg.author) { - await interaction.message.delete(); - } else { - await interaction.reply({ - content: 'You can only delete your own messages!', - ephemeral: true, - }); - } - } - } - if (interaction.isChatInputCommand()) { const { commandName } = interaction; @@ -129,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') {