Skip to content

Commit

Permalink
[api/commands] Resupport execute return
Browse files Browse the repository at this point in the history
  • Loading branch information
pylixonly committed Apr 3, 2024
1 parent 1e41fe3 commit 9fbbf5b
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/lib/api/commands/index.ts
Original file line number Diff line number Diff line change
@@ -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[] = [];

Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit 9fbbf5b

Please sign in to comment.