A powerful and extendable Discord bot, with it's own module system :3 thevoid.cafe/projects/voidy
at develop 47 lines 1.7 kB view raw
1import { MessageFlags, PermissionFlagsBits, SlashCommandSubcommandBuilder } from "discord.js"; 2import { Command, requirePermission } from "@voidy/framework"; 3import { ChatbotRepository } from "../../schemas/ChatbotRepository"; 4 5export default new Command({ 6 id: "chatbot.message.add", 7 use: [requirePermission(PermissionFlagsBits.ManageGuild)], 8 data: new SlashCommandSubcommandBuilder() 9 .setName("add") 10 .setDescription("Add a message to a content repository.") 11 .addStringOption((option) => 12 option.setName("content").setDescription("Message content. Use <age> for random 1-12.").setRequired(true), 13 ) 14 .addStringOption((option) => 15 option 16 .setName("repository") 17 .setDescription("Local repository name. Omit for global."), 18 ), 19 20 execute: async ({ interaction }) => { 21 const content = interaction.options.getString("content", true); 22 const repoName = interaction.options.getString("repository"); 23 24 const query = repoName 25 ? { scope: "local" as const, guildId: interaction.guildId, name: repoName } 26 : { scope: "global" as const }; 27 28 const repo = await ChatbotRepository.findOne(query); 29 30 if (!repo) { 31 const target = repoName ? `Local repository "${repoName}"` : "Global repository"; 32 await interaction.reply({ 33 content: `${target} not found.`, 34 flags: [MessageFlags.Ephemeral], 35 }); 36 return; 37 } 38 39 repo.messages.push({ content, addedBy: interaction.user.id }); 40 await repo.save(); 41 42 await interaction.reply({ 43 content: `Message added to **${repo.name}** (${repo.scope}). Total: ${repo.messages.length}.`, 44 flags: [MessageFlags.Ephemeral], 45 }); 46 }, 47});