pub struct Command<U, E> {Show 38 fields
pub prefix_action: Option<for<'a> fn(PrefixContext<'a, U, E>) -> BoxFuture<'a, Result<(), FrameworkError<'a, U, E>>>>,
pub slash_action: Option<for<'a> fn(ApplicationContext<'a, U, E>) -> BoxFuture<'a, Result<(), FrameworkError<'a, U, E>>>>,
pub context_menu_action: Option<ContextMenuCommandAction<U, E>>,
pub subcommands: Vec<Command<U, E>>,
pub subcommand_required: bool,
pub name: String,
pub name_localizations: HashMap<String, String>,
pub qualified_name: String,
pub identifying_name: String,
pub source_code_name: String,
pub category: Option<String>,
pub hide_in_help: bool,
pub description: Option<String>,
pub description_localizations: HashMap<String, String>,
pub help_text: Option<String>,
pub manual_cooldowns: Option<bool>,
pub cooldowns: Mutex<CooldownTracker>,
pub cooldown_config: RwLock<CooldownConfig>,
pub reuse_response: bool,
pub default_member_permissions: Permissions,
pub required_permissions: Permissions,
pub required_bot_permissions: Permissions,
pub owners_only: bool,
pub guild_only: bool,
pub dm_only: bool,
pub nsfw_only: bool,
pub on_error: Option<fn(FrameworkError<'_, U, E>) -> BoxFuture<'_, ()>>,
pub checks: Vec<fn(Context<'_, U, E>) -> BoxFuture<'_, Result<bool, E>>>,
pub parameters: Vec<CommandParameter<U, E>>,
pub custom_data: Box<dyn Any + Send + Sync>,
pub aliases: Vec<String>,
pub invoke_on_edit: bool,
pub track_deletion: bool,
pub broadcast_typing: bool,
pub context_menu_name: Option<String>,
pub ephemeral: bool,
pub install_context: Option<Vec<InstallationContext>>,
pub interaction_context: Option<Vec<InteractionContext>>,
/* private fields */
}
Expand description
Type returned from #[poise::command]
annotated functions, which contains all of the generated
prefix and application commands
Fields§
§prefix_action: Option<for<'a> fn(PrefixContext<'a, U, E>) -> BoxFuture<'a, Result<(), FrameworkError<'a, U, E>>>>
Callback to execute when this command is invoked in a prefix context
slash_action: Option<for<'a> fn(ApplicationContext<'a, U, E>) -> BoxFuture<'a, Result<(), FrameworkError<'a, U, E>>>>
Callback to execute when this command is invoked in a slash context
Callback to execute when this command is invoked in a context menu context
The enum variant shows which Discord item this context menu command works on
subcommands: Vec<Command<U, E>>
Subcommands of this command, if any
subcommand_required: bool
Require a subcommand to be invoked
name: String
Main name of the command. Aliases (prefix-only) can be set in Self::aliases
.
name_localizations: HashMap<String, String>
Localized names with locale string as the key (slash-only)
qualified_name: String
Full name including parent command names.
Initially set to just Self::name
and properly populated when the framework is started.
identifying_name: String
A string to identify this particular command within a list of commands.
Can be configured via the crate::command
macro (though it’s probably not needed for most
bots). If not explicitly configured, it falls back to the command function name.
source_code_name: String
The name of the #[poise::command]
-annotated function
category: Option<String>
Identifier for the category that this command will be displayed in for help commands.
hide_in_help: bool
Whether to hide this command in help menus.
description: Option<String>
Short description of the command. Displayed inline in help menus and similar.
description_localizations: HashMap<String, String>
Localized descriptions with locale string as the key (slash-only)
help_text: Option<String>
Multiline description with detailed usage instructions. Displayed in the command specific
help: ~help command_name
manual_cooldowns: Option<bool>
if true
, disables automatic cooldown handling before this commands invocation.
Will override crate::FrameworkOptions::manual_cooldowns
allowing manual cooldowns
on select commands.
cooldowns: Mutex<CooldownTracker>
Handles command cooldowns. Mainly for framework internal use
cooldown_config: RwLock<CooldownConfig>
Configuration for the crate::CooldownTracker
reuse_response: bool
After the first response, whether to post subsequent responses as edits to the initial message
Note: in prefix commands, this only has an effect if
crate::PrefixFrameworkOptions::edit_tracker
is set.
default_member_permissions: Permissions
Permissions which users must have to invoke this command. Used by Discord to set who can invoke this as a slash command. Not used on prefix commands or checked internally.
Set to serenity::Permissions::empty()
by default
required_permissions: Permissions
Permissions which users must have to invoke this command. This is checked internally and works for both prefix commands and slash commands.
Set to serenity::Permissions::empty()
by default
required_bot_permissions: Permissions
Permissions without which command execution will fail. You can set this to fail early and give a descriptive error message in case the bot hasn’t been assigned the minimum permissions by the guild admin.
Set to serenity::Permissions::empty()
by default
owners_only: bool
If true, only users from the owners list may use this command.
guild_only: bool
If true, only people in guilds may use this command
dm_only: bool
If true, the command may only run in DMs
nsfw_only: bool
If true, the command may only run in NSFW channels
on_error: Option<fn(FrameworkError<'_, U, E>) -> BoxFuture<'_, ()>>
Command-specific override for crate::FrameworkOptions::on_error
checks: Vec<fn(Context<'_, U, E>) -> BoxFuture<'_, Result<bool, E>>>
If any of these functions returns false, this command will not be executed.
parameters: Vec<CommandParameter<U, E>>
List of parameters for this command
Used for registering and parsing slash commands. Can also be used in help commands
custom_data: Box<dyn Any + Send + Sync>
Arbitrary data, useful for storing custom metadata about your commands
aliases: Vec<String>
Alternative triggers for the command (prefix-only)
invoke_on_edit: bool
Whether to rerun the command if an existing invocation message is edited (prefix-only)
track_deletion: bool
Whether to delete the bot response if an existing invocation message is deleted (prefix-only)
broadcast_typing: bool
Whether to broadcast a typing indicator while executing this commmand (prefix-only)
Context menu specific name for this command, displayed in Discord’s context menu
ephemeral: bool
Whether responses to this command should be ephemeral by default (application-only)
install_context: Option<Vec<InstallationContext>>
List of installation contexts for this command (application-only)
interaction_context: Option<Vec<InteractionContext>>
List of interaction contexts for this command (application-only)
Implementations§
Source§impl<U, E> Command<U, E>
impl<U, E> Command<U, E>
Sourcepub fn create_as_slash_command(&self) -> Option<CreateCommand>
pub fn create_as_slash_command(&self) -> Option<CreateCommand>
Generates a slash command builder from this Command
instance. This can be used
to register this command on Discord’s servers
Generates a context menu command builder from this Command
instance. This can be used
to register this command on Discord’s servers
Trait Implementations§
impl<U, E> Eq for Command<U, E>
Auto Trait Implementations§
impl<U, E> !Freeze for Command<U, E>
impl<U, E> !RefUnwindSafe for Command<U, E>
impl<U, E> Send for Command<U, E>
impl<U, E> Sync for Command<U, E>
impl<U, E> Unpin for Command<U, E>
impl<U, E> !UnwindSafe for Command<U, E>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.