[api/commands] Resupport execute return

This commit is contained in:
amsyarasyiq 2024-04-03 15:06:51 +08:00
parent 1e41fe3601
commit 9fbbf5bb2f

View file

@ -1,6 +1,7 @@
import { ApplicationCommand, ApplicationCommandInputType, ApplicationCommandType } from "@lib/api/commands/types";
import { after } from "@lib/api/patcher";
import { commands as commandsModule } from "@metro/common";
import { after, instead } from "@lib/api/patcher";
import { logger } from "@lib/utils/logger";
import { commands as commandsModule, messageUtil } from "@metro/common";
let commands: ApplicationCommand[] = [];
@ -48,6 +49,18 @@ export function registerCommand(command: ApplicationCommand): () => void {
opt.displayDescription ??= opt.description;
}
instead("execute", command, (args, orig) => {
Promise.resolve(
orig.apply(command, args)
).then(ret => {
if (ret && typeof ret === "object") {
messageUtil.sendMessage(args[1].channel.id, ret);
}
}).catch(err => {
logger.error("Failed to execute command", err);
});
});
// Add it to the commands array
commands.push(command);