pub struct ContextMenuCommandBuilder { /* private fields */ }Expand description
Builds a context-menu command: an entry in the “Apps” menu of a user or of a message, with a name and no options.
The name can have 1-32 characters of any kind — upper-case letters, spaces and emoji are fine (D-195). Register the result like a slash command.
discord.js counterpart: ContextMenuCommandBuilder (the type is chosen by the constructor
instead of setType).
§Examples
use djs_builders::ContextMenuCommandBuilder;
use djs_model::{application_command::CommandType, util::Locale};
let report = ContextMenuCommandBuilder::message("Report message")
.name_localization(Locale::Polish, "Zgłoś wiadomość")
.build()
.unwrap();
assert_eq!(report.kind, Some(CommandType::Message));
assert_eq!(report.description, None);
let profile = ContextMenuCommandBuilder::user("Show profile").build().unwrap();
assert_eq!(profile.kind, Some(CommandType::User));Implementations§
Source§impl ContextMenuCommandBuilder
impl ContextMenuCommandBuilder
Sourcepub fn user(name: impl Into<CompactString>) -> Self
pub fn user(name: impl Into<CompactString>) -> Self
Creates a command in the context menu of users, named name (1-32 characters).
discord.js counterpart: setType(ApplicationCommandType.User).
Sourcepub fn message(name: impl Into<CompactString>) -> Self
pub fn message(name: impl Into<CompactString>) -> Self
Creates a command in the context menu of messages, named name (1-32 characters).
discord.js counterpart: setType(ApplicationCommandType.Message).
Sourcepub fn name_localization(
self,
locale: Locale,
name: impl Into<CompactString>,
) -> Self
pub fn name_localization( self, locale: Locale, name: impl Into<CompactString>, ) -> Self
Sets the name shown to users whose Discord language is locale. It follows the same
rules as the name itself.
discord.js counterpart: setNameLocalization.
Sourcepub fn name_localizations<N: Into<CompactString>>(
self,
localizations: impl IntoIterator<Item = (Locale, N)>,
) -> Self
pub fn name_localizations<N: Into<CompactString>>( self, localizations: impl IntoIterator<Item = (Locale, N)>, ) -> Self
Sets several name translations at once, keeping those set before (a locale given again gets the new name).
discord.js counterpart: setNameLocalizations (which replaces them all).
Sourcepub fn default_member_permissions(self, permissions: Permissions) -> Self
pub fn default_member_permissions(self, permissions: Permissions) -> Self
Sets the permissions a member needs to use the command by default; server
administrators can change who may use it.
Permissions::empty() limits it to
administrators. Without this, everyone can use it.
discord.js counterpart: setDefaultMemberPermissions.
Sourcepub fn contexts(
self,
contexts: impl IntoIterator<Item = InteractionContextType>,
) -> Self
pub fn contexts( self, contexts: impl IntoIterator<Item = InteractionContextType>, ) -> Self
Sets where the command can be used: in servers, in DMs with the bot, and in other DMs and group DMs. Without this, Discord allows all of them.
discord.js counterpart: setContexts.
Sourcepub fn integration_types(
self,
integration_types: impl IntoIterator<Item = IntegrationType>,
) -> Self
pub fn integration_types( self, integration_types: impl IntoIterator<Item = IntegrationType>, ) -> Self
Sets which installations offer the command: the app installed to a server, to a user, or both. Without this, Discord uses the installation types the app supports.
discord.js counterpart: setIntegrationTypes.
Sourcepub fn nsfw(self, nsfw: bool) -> Self
pub fn nsfw(self, nsfw: bool) -> Self
Marks the command as age-restricted, so it can only be used in age-restricted channels.
discord.js counterpart: setNSFW.
Sourcepub fn build(self) -> Result<CreateApplicationCommand, ValidationError>
pub fn build(self) -> Result<CreateApplicationCommand, ValidationError>
Checks the name and its translations (1-32 characters, not blank) and returns the command.
discord.js counterpart: ContextMenuCommandBuilder#toJSON.
§Errors
ValidationError::Missing for a blank name, ValidationError::TooLong for one
above 32 characters.
Sourcepub fn build_unchecked(self) -> CreateApplicationCommand
pub fn build_unchecked(self) -> CreateApplicationCommand
Returns the command without any check (D-180).
discord.js counterpart: ContextMenuCommandBuilder#toJSON with validation off (disableValidators).