-
Notifications
You must be signed in to change notification settings - Fork 121
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: subcommmand_required parameter (#170)
* Add Infallible to __NonExhaustive enum variants * add: subcommmand_required * Fix a few things - The code was not properly formatted (`cargo fmt --all`) - There was a redundant is_subcommand value added to a bunch of things (including find_command - this PR was a breaking change and would have belonged to the `next` branch! But since is_subcommand was redundant and I removed it, this PR becomes not-breaking again (which makes sense; this kind of small feature shouldn't need breaking changes)) - The is_subcommand check was in the wrong place. The parse_invocation is really only for parsing, not for any action. If it returns an error, it should be an error in _parsing_, not in execution or usage. And it also belongs after the track_edits related checks, because if a message was edited that poise isn't even allowed to care about, it shouldn't throw an error too (this would have been another problem with the is_subcommand check in parse_invocation) * Improve text --------- Co-authored-by: kangalioo <jannik.a.schaper@web.de> Co-authored-by: xtfdfr <sadorowo@gmail.com>
- Loading branch information
1 parent
ae180fd
commit 7866109
Showing
8 changed files
with
91 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
use crate::{Context, Error}; | ||
|
||
/// A command with two subcommands: `child1` and `child2` | ||
/// | ||
/// Running this function directly, without any subcommand, is only supported in prefix commands. | ||
/// Discord doesn't permit invoking the root command of a slash command if it has subcommands. | ||
/// This command can be invoked only with `parent child1` and `parent child2`, due to `subcommand_required` parameter. | ||
/// If you want to allow `parent` to be invoked without subcommand, remove `subcommand_required` parameter | ||
#[poise::command( | ||
prefix_command, | ||
slash_command, | ||
subcommands("child1", "child2"), | ||
subcommand_required | ||
)] | ||
// Omit 'ctx' parameter here. It is not needed, because this function will never be called. | ||
// TODO: Add a way to remove 'ctx' parameter, when `subcommand_required` is set | ||
pub async fn parent_subcommand_required(_: Context<'_>) -> Result<(), Error> { | ||
// This will never be called, because `subcommand_required` parameter is set | ||
Ok(()) | ||
} | ||
|
||
/// A subcommand of `parent` | ||
#[poise::command(prefix_command, slash_command)] | ||
pub async fn child1(ctx: Context<'_>) -> Result<(), Error> { | ||
ctx.say("You invoked the first child command!").await?; | ||
Ok(()) | ||
} | ||
|
||
/// Another subcommand of `parent` | ||
#[poise::command(prefix_command, slash_command)] | ||
pub async fn child2(ctx: Context<'_>) -> Result<(), Error> { | ||
ctx.say("You invoked the second child command!").await?; | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters