Skip to content

Commit

Permalink
Add optional min/max length fields for application command string opt…
Browse files Browse the repository at this point in the history
…ions (#2038)
  • Loading branch information
nickelc committed Jul 14, 2022
1 parent 11918e7 commit 46707e4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/builder/create_application_command.rs
Expand Up @@ -273,6 +273,24 @@ impl CreateApplicationCommandOption {

self
}

/// Sets the minimum permitted length for this string option.
///
/// The value of `min_length` must be greater or equal to `0`.
pub fn min_length(&mut self, value: u16) -> &mut Self {
self.0.insert("min_length", value.into());

self
}

/// Sets the maximum permitted length for this string option.
///
/// The value of `max_length` must be greater or equal to `1`.
pub fn max_length(&mut self, value: u16) -> &mut Self {
self.0.insert("max_length", value.into());

self
}
}

/// A builder for creating a new [`Command`].
Expand Down
6 changes: 6 additions & 0 deletions src/model/application/command.rs
Expand Up @@ -322,6 +322,12 @@ pub struct CommandOption {
/// Maximum permitted value for Integer or Number options
#[serde(default)]
pub max_value: Option<serde_json::Number>,
/// Minimum permitted length for String options
#[serde(default)]
pub min_length: Option<u16>,
/// Maximum permitted length for String options
#[serde(default)]
pub max_length: Option<u16>,
#[serde(default)]
pub autocomplete: bool,
}
Expand Down

0 comments on commit 46707e4

Please sign in to comment.