User Input Validators

This module is a compilation of user input validators.

class Validator[source]

Base class for all validators.

Parameters
  • message (discord.Message) – The message which triggered the validation.

  • on_error (Dict) – A dictionary containing error heading and content.

  • dm_user (bool) – Route the message to user’s DM?

  • notify (bool) – Notify the user if the validation fails?

property error_embed: Embed

Returns an error embed.

Returns

An error embed.

Return type

discord.Embed

property null_embed: Embed

Returns a null embed.

Returns

A null embed.

Return type

discord.Embed

async validate()[source]

Validates the given value.

Parameters

value (str) – The value to be validated.

Returns

True if the value is valid, False otherwise.

Return type

bool

async cleaned()[source]

Cleans the given value after validation.

Parameters

value (Any) –

Return type

Any

class ChainValidator[source]

Chain multiple validators together.

Parameters

validator_spec (Dict[Validator, Dict[str, Any]]) – Validator and Kwargs mapping.

class IntegerValidator[source]

Validates an integer value.

error_embed_desc = 'Please enter a valid integer.'
cleaner

alias of int

class MaxValidator[source]

Validates a value is less than or equal to the maximum.

Parameters

max_value (int) – The maximum value to validate against.

Kwargs

Additional keyword arguments to pass to the superclass.

class MinValidator[source]

Validates a value is greater than or equal to the minimum.

Parameters

min_value (int) – The minimum value to validate against.

Kwargs

Additional keyword arguments to pass to the superclass.

class MaxLengthValidator[source]

Validates a string to be of a certain length.

Parameters

max_length (int) – The maximum permissible length of the string.

Kwargs

Additional keyword arguments to pass to the superclass.

error_embed_desc = 'Input value has too many characters.'
class MinLengthValidator[source]

Validates a string to be of a certain length.

Parameters

min_length (int) – The minimum permissible length of the string.

Kwargs

Additional keyword arguments to pass to the superclass.

error_embed_desc = 'Input value has too few characters.'
class RegexValidator[source]

Validates a string against a regular expression.

Parameters

pattern (str) – The regular expression to use for validation.

class HexValidator[source]

Validates if a string is a hexadecimal value.

error_embed_title = 'Invalid Hexadecimal value'
static cleaner()[source]

Converts a hexadecimal string to an integer. :param hex_str: The hexadecimal string to convert. :type hex_str: str :return: The integer value of the hexadecimal string. :rtype: int

Parameters

hex_str (str) –

Return type

int

class ImageUrlValidator[source]

Validates if a strings is an image URL.

error_embed_title = 'Invalid image URL'
error_embed_desc = 'Only Png and JPG images are supported.'
class UrlValidator[source]

Validates if a string is a URL.

error_embed_title = 'Invalid URL'
class ItemNameValidator[source]

Validates if a string is a valid item name.

error_embed_title = 'Invalid Item Name'