diff --git a/src/_reupload.ts b/src/_reupload.ts index cdb102c..d4bc3ec 100644 --- a/src/_reupload.ts +++ b/src/_reupload.ts @@ -36,16 +36,19 @@ import 'dotenv/config'; .addStringOption((option) => option.setName('id').setDescription('The ID or slug').setRequired(true) ), + new SlashCommandBuilder() + .setName('say') + .setDescription('Say someothing through the bot') + .addStringOption((option) => + option + .setName('content') + .setDescription('Just content?') + .setRequired(true) + ), ].map((command) => command.toJSON()); const rest = new REST({ version: '10' }).setToken(process.env.DISCORD_TOKEN!); - await rest.put(Routes.applicationCommands(process.env.DISCORD_APP!), { - body: [], - }); - - console.log('Successfully deleted all application commands.'); - await rest.put(Routes.applicationCommands(process.env.DISCORD_APP!), { body: commands, }); diff --git a/src/commands/members.ts b/src/commands/members.ts index 11d730e..45d4dcc 100644 --- a/src/commands/members.ts +++ b/src/commands/members.ts @@ -1,8 +1,10 @@ -import type { CacheType, CommandInteraction } from 'discord.js'; +import type { CacheType, ChatInputCommandInteraction } from 'discord.js'; import { COLORS } from '../constants'; -export const membersCommand = async (i: CommandInteraction) => { +export const membersCommand = async ( + i: ChatInputCommandInteraction +) => { await i.deferReply(); const memes = await i.guild?.members.fetch().then((r) => r.toJSON()); diff --git a/src/commands/modrinth.ts b/src/commands/modrinth.ts index d240487..a077928 100644 --- a/src/commands/modrinth.ts +++ b/src/commands/modrinth.ts @@ -15,14 +15,16 @@ export interface ModrinthProject { } import { - type CacheType, - type CommandInteraction, EmbedBuilder, + type CacheType, + type ChatInputCommandInteraction, } from 'discord.js'; import { COLORS } from '../constants'; -export const modrinthCommand = async (i: CommandInteraction) => { +export const modrinthCommand = async ( + i: ChatInputCommandInteraction +) => { await i.deferReply(); const { value: id } = i.options.get('id') ?? { value: null }; diff --git a/src/commands/stars.ts b/src/commands/stars.ts index 753e3c8..8b65c63 100644 --- a/src/commands/stars.ts +++ b/src/commands/stars.ts @@ -1,7 +1,9 @@ -import type { CacheType, CommandInteraction } from 'discord.js'; +import type { CacheType, ChatInputCommandInteraction } from 'discord.js'; import { COLORS } from '../constants'; -export const starsCommand = async (i: CommandInteraction) => { +export const starsCommand = async ( + i: ChatInputCommandInteraction +) => { await i.deferReply(); const count = await fetch('https://api.github.com/repos/PolyMC/PolyMC') diff --git a/src/commands/tags.ts b/src/commands/tags.ts new file mode 100644 index 0000000..98304e2 --- /dev/null +++ b/src/commands/tags.ts @@ -0,0 +1,36 @@ +import { + type ChatInputCommandInteraction, + type CacheType, + EmbedBuilder, +} from 'discord.js'; +import { getTags } from '../tagsTags'; + +export const tagsCommand = async ( + i: ChatInputCommandInteraction +) => { + const tags = await getTags(); + const tagName = i.options.getString('name', true); + const tag = tags.find( + (tag) => tag.name === tagName || tag.aliases?.includes(tagName) + ); + + if (!tag) { + await i.reply({ + content: `Tag \`${tagName}\` does not exist.`, + ephemeral: true, + }); + return; + } + + await i.reply({ + content: tag.text ? `**${tag.name}**\n\n` + tag.text : tag.text, + embeds: tag.embed + ? [ + new EmbedBuilder(tag.embed).setFooter({ + text: `Requested by ${i.user.tag}`, + iconURL: i.user.avatarURL() ?? undefined, + }), + ] + : [], + }); +}; diff --git a/src/index.ts b/src/index.ts index 6acd8e1..c860137 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,11 +1,4 @@ -import { - Client, - EmbedBuilder, - GatewayIntentBits, - Partials, - ChannelType, - OAuth2Scopes, -} from 'discord.js'; +import { Client, GatewayIntentBits, Partials, OAuth2Scopes } from 'discord.js'; import * as BuildConfig from './constants'; import { parseLog } from './logs'; @@ -13,12 +6,12 @@ import { getLatestMinecraftVersion } from './utils/remoteVersions'; import { membersCommand } from './commands/members'; import { starsCommand } from './commands/stars'; +import { modrinthCommand } from './commands/modrinth'; +import { tagsCommand } from './commands/tags'; import random from 'just-random'; import { green, bold, yellow } from 'kleur/colors'; import 'dotenv/config'; -import { getTags } from './tagsTags'; -import { modrinthCommand } from './commands/modrinth'; const client = new Client({ intents: [ @@ -117,32 +110,13 @@ client.on('interactionCreate', async (interaction) => { await interaction.reply( 'https://media.discordapp.net/attachments/985048903126769764/985051373886382100/rollin-time.gif?width=324&height=216' ); + } else if (commandName === 'say') { + if (!interaction.channel) return; + await interaction.deferReply(); + await interaction.channel.send(interaction.options.getString('content')!); + await interaction.editReply('I said what you said!'); } else if (commandName === 'tag') { - const tags = await getTags(); - const tagName = interaction.options.getString('name', true); - const tag = tags.find( - (tag) => tag.name === tagName || tag.aliases?.includes(tagName) - ); - - if (!tag) { - await interaction.reply({ - content: `Tag \`${tagName}\` does not exist.`, - ephemeral: true, - }); - return; - } - - await interaction.reply({ - content: tag.text ? `**${tag.name}**\n\n` + tag.text : tag.text, - embeds: tag.embed - ? [ - new EmbedBuilder(tag.embed).setFooter({ - text: `Requested by ${interaction.user.tag}`, - iconURL: interaction.user.avatarURL() ?? undefined, - }), - ] - : [], - }); + tagsCommand(interaction); } });