From 0473e32b39f4202b899eb60ff229bcbb7d47f96c Mon Sep 17 00:00:00 2001 From: fzzinchemical Date: Tue, 15 Apr 2025 06:40:39 +0200 Subject: [PATCH] added async execute test --- src/bot.ts | 25 +++++++++++-- src/plugins/rule34/commands.ts | 63 ++++++++++++++++++++------------- src/plugins/yandere/commands.ts | 14 ++++---- 3 files changed, 69 insertions(+), 33 deletions(-) diff --git a/src/bot.ts b/src/bot.ts index be2653c..300ca4d 100755 --- a/src/bot.ts +++ b/src/bot.ts @@ -1,9 +1,11 @@ import { +ChatInputCommandInteraction, Client, Events, GatewayIntentBits, REST, Routes, + SlashCommandBuilder, } from "@discordjs"; import * as stdDotenv from "jsr:@std/dotenv@0.225.3"; import { commandRouter } from "@root/commands.ts"; @@ -45,7 +47,26 @@ client.on(Events.Error, (e) => { reject(e); }); -const commands = commandRouter() +// const commands = commandRouter() +//test +const commands = { + data: new SlashCommandBuilder() + .setName('gif') + .setDescription('Sends a random gif!') + .addStringOption(option => + option.setName('category') + .setDescription('The gif category') + .setRequired(true) + .addChoices( + { name: 'Funny', value: 'gif_funny' }, + { name: 'Meme', value: 'gif_meme' }, + { name: 'Movie', value: 'gif_movie' }, + )), + async execute(interaction: ChatInputCommandInteraction) { + const category = interaction.options.getString('category'); + await interaction.reply(`You chose: ${category}`); + }, +}; const rest = new REST({ version: "10" }).setToken(token); @@ -59,7 +80,7 @@ try { await rest.put( Routes.applicationCommands(client.application.id), { - body: commands, + body: [commands], }, ); diff --git a/src/plugins/rule34/commands.ts b/src/plugins/rule34/commands.ts index 422a4c3..11434c0 100644 --- a/src/plugins/rule34/commands.ts +++ b/src/plugins/rule34/commands.ts @@ -1,4 +1,9 @@ -import { SlashCommandBuilder } from "@discordjs"; +import { +ChatInputCommandInteraction, + CommandInteractionOptionResolver, + InteractionCallback, + SlashCommandBuilder, +} from "@discordjs"; // import { drop, help, requestWorker } from "./plugin.ts"; import { logMessage } from "@root/logging.ts"; import { defaultString } from "@root/defaultString.ts"; @@ -19,7 +24,7 @@ import { defaultString } from "@root/defaultString.ts"; // } // } else if (command === "help") { // logMessage(message); - + // bot.helpers.sendMessage(message.channelId, { // content: defaultString(help()), // }); @@ -29,26 +34,34 @@ import { defaultString } from "@root/defaultString.ts"; // } export const commands = [ - new SlashCommandBuilder() - .setName("rule") - .setDescription("Drops one or multiple images using the rule34 API.") - .setNSFW(true) - .addSubcommand(subcommand => - subcommand - .setName("drop") - .setDescription("Drops one or multiple images using the rule34 API.") - - ), - new SlashCommandBuilder() - .setName('gif') - .setDescription('Sends a random gif!') - .addStringOption(option => - option.setName('category') - .setDescription('The gif category') - .setRequired(true) - .addChoices( - { name: 'Funny', value: 'gif_funny' }, - { name: 'Meme', value: 'gif_meme' }, - { name: 'Movie', value: 'gif_movie' }, - )) -] \ No newline at end of file + { + data: new SlashCommandBuilder() + .setName("rule") + .setDescription("Drops one or multiple images using the rule34 API.") + .setNSFW(true) + .addSubcommand((subcommand) => + subcommand + .setName("drop") + .setDescription("Drops one or multiple images using the rule34 API.") + ), + }, + { + data: new SlashCommandBuilder() + .setName("gif") + .setDescription("Sends a random gif!") + .addStringOption((option) => + option.setName("category") + .setDescription("The gif category") + .setRequired(true) + .addChoices( + { name: "Funny", value: "gif_funny" }, + { name: "Meme", value: "gif_meme" }, + { name: "Movie", value: "gif_movie" }, + ) + ), + async execute (interaction: ChatInputCommandInteraction) { + const category = interaction.options.getString('category'); + await interaction.reply(`You chose: ${category}`); + } + }, +]; diff --git a/src/plugins/yandere/commands.ts b/src/plugins/yandere/commands.ts index e93c2d7..5bb28f0 100644 --- a/src/plugins/yandere/commands.ts +++ b/src/plugins/yandere/commands.ts @@ -1,4 +1,4 @@ -import { SlashCommandBuilder} from "@discordjs"; +import { SlashCommandBuilder } from "@discordjs"; import { logMessage } from "@root/logging.ts"; import { getPosts } from "@root/plugins/yandere/api/api.ts"; @@ -24,8 +24,10 @@ import { getPosts } from "@root/plugins/yandere/api/api.ts"; // } export const commands = [ - new SlashCommandBuilder() - .setName("drop") - .setDescription("Drops one or multiple images using the yande.re API.") - .setNSFW(true) -] \ No newline at end of file + { + data: new SlashCommandBuilder() + .setName("drop") + .setDescription("Drops one or multiple images using the yande.re API.") + .setNSFW(true), + }, +];