Skip to main content

ContextMenuCommandBuilder

Struct ContextMenuCommandBuilder 

Source
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

Source

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).

Source

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).

Source

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.

Source

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).

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn build_unchecked(self) -> CreateApplicationCommand

Returns the command without any check (D-180).

discord.js counterpart: ContextMenuCommandBuilder#toJSON with validation off (disableValidators).

Trait Implementations§

Source§

impl Clone for ContextMenuCommandBuilder

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ContextMenuCommandBuilder

Source§

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

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

impl PartialEq for ContextMenuCommandBuilder

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for ContextMenuCommandBuilder

Auto Trait Implementations§

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<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.