Invoking Command method from other command
Hey all, I’m not really sure if this is a “Sapphire support” type of question more than a TypeScript one (I’m new to TS in general)
But is there any way to invoke a commands messageRun or the designated method from say another command class (something like Java reflection/does sapphire have a command handler to grab the appropriate method?) or is the best way to extract the code to a new file then just call that from both commands?
Basically I have a command which is:
$account link <region> <account name>
But I also have another command which is:
$verify <region> <account name>
or
$verify <account name>
Is there any way for me to just have the verify commands call the: $account link chat input method
Or is the best way to just have like a Verification.ts and have the command logic in there and call that method from every command.
Honestly just trying to minimize ts files if possible
Solution:Jump to solution
You can leverage
this.store
, just make sure you pas all the right arguments:
```ts
import { Args, Command, type MessageCommand } from '@sapphire/framework';
import type { Message } from 'discord.js';...5 Replies
Solution
You can leverage
this.store
, just make sure you pas all the right arguments:
Thanks, this is perfectly what I need
Okay, well one further question, can this be done with subcommands?
yes - but
1. If you want the full flow including parsing and preconditions you'll have to make sure the args have all the proper data of subcommand group/name etc
2. If you just want to call your own subcommand method you'll have to do some type casting because TS won't know what methods are on the class, then pass the parameters
Ah okay