added async execute test

This commit is contained in:
fzzinchemical
2025-04-15 06:40:39 +02:00
parent 1f3090d799
commit 0473e32b39
3 changed files with 69 additions and 33 deletions

View File

@@ -1,9 +1,11 @@
import { import {
ChatInputCommandInteraction,
Client, Client,
Events, Events,
GatewayIntentBits, GatewayIntentBits,
REST, REST,
Routes, Routes,
SlashCommandBuilder,
} from "@discordjs"; } from "@discordjs";
import * as stdDotenv from "jsr:@std/dotenv@0.225.3"; import * as stdDotenv from "jsr:@std/dotenv@0.225.3";
import { commandRouter } from "@root/commands.ts"; import { commandRouter } from "@root/commands.ts";
@@ -45,7 +47,26 @@ client.on(Events.Error, (e) => {
reject(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); const rest = new REST({ version: "10" }).setToken(token);
@@ -59,7 +80,7 @@ try {
await rest.put( await rest.put(
Routes.applicationCommands(client.application.id), Routes.applicationCommands(client.application.id),
{ {
body: commands, body: [commands],
}, },
); );

View File

@@ -1,4 +1,9 @@
import { SlashCommandBuilder } from "@discordjs"; import {
ChatInputCommandInteraction,
CommandInteractionOptionResolver,
InteractionCallback,
SlashCommandBuilder,
} from "@discordjs";
// import { drop, help, requestWorker } from "./plugin.ts"; // import { drop, help, requestWorker } from "./plugin.ts";
import { logMessage } from "@root/logging.ts"; import { logMessage } from "@root/logging.ts";
import { defaultString } from "@root/defaultString.ts"; import { defaultString } from "@root/defaultString.ts";
@@ -29,26 +34,34 @@ import { defaultString } from "@root/defaultString.ts";
// } // }
export const commands = [ export const commands = [
new SlashCommandBuilder() {
data: new SlashCommandBuilder()
.setName("rule") .setName("rule")
.setDescription("Drops one or multiple images using the rule34 API.") .setDescription("Drops one or multiple images using the rule34 API.")
.setNSFW(true) .setNSFW(true)
.addSubcommand(subcommand => .addSubcommand((subcommand) =>
subcommand subcommand
.setName("drop") .setName("drop")
.setDescription("Drops one or multiple images using the rule34 API.") .setDescription("Drops one or multiple images using the rule34 API.")
), ),
new SlashCommandBuilder() },
.setName('gif') {
.setDescription('Sends a random gif!') data: new SlashCommandBuilder()
.addStringOption(option => .setName("gif")
option.setName('category') .setDescription("Sends a random gif!")
.setDescription('The gif category') .addStringOption((option) =>
option.setName("category")
.setDescription("The gif category")
.setRequired(true) .setRequired(true)
.addChoices( .addChoices(
{ name: 'Funny', value: 'gif_funny' }, { name: "Funny", value: "gif_funny" },
{ name: 'Meme', value: 'gif_meme' }, { name: "Meme", value: "gif_meme" },
{ name: 'Movie', value: 'gif_movie' }, { name: "Movie", value: "gif_movie" },
)) )
] ),
async execute (interaction: ChatInputCommandInteraction) {
const category = interaction.options.getString('category');
await interaction.reply(`You chose: ${category}`);
}
},
];

View File

@@ -1,4 +1,4 @@
import { SlashCommandBuilder} from "@discordjs"; import { SlashCommandBuilder } from "@discordjs";
import { logMessage } from "@root/logging.ts"; import { logMessage } from "@root/logging.ts";
import { getPosts } from "@root/plugins/yandere/api/api.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 = [ export const commands = [
new SlashCommandBuilder() {
data: new SlashCommandBuilder()
.setName("drop") .setName("drop")
.setDescription("Drops one or multiple images using the yande.re API.") .setDescription("Drops one or multiple images using the yande.re API.")
.setNSFW(true) .setNSFW(true),
] },
];