Struct Command

Source
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

§context_menu_action: Option<ContextMenuCommandAction<U, E>>

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_name: Option<String>

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>

Source

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

Source

pub fn create_as_context_menu_command(&self) -> Option<CreateCommand>

Generates a context menu command builder from this Command instance. This can be used to register this command on Discord’s servers

Trait Implementations§

Source§

impl<U, E> Debug for Command<U, E>

Source§

fn fmt(&self, __f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<U, E> Default for Command<U, E>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<U, E> PartialEq for Command<U, E>

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> DebuggableStorage for T
where T: Any + Send + Sync + Debug,

Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MaybeSendSync for T