Skip to content

argument

Base classes for the types used within Helply.

Argument dataclass

Represents a SlashCommand argument.

Attributes:

  • name (str) –

    Argument's non-localized name

  • description (str) –

    Argument's non-localized description

  • required (bool) –

    Whether or not the argument is required.

  • name_localizations (LocalizationValue) –

    Contains localizations for the argument's name. (New in version 0.3.0)

  • description_localizations (LocalizationValue) –

    Contains localizations for the argument's description. (New in version 0.3.0)

Methods:

  • get_localized_name

    Return localized or non-localized name. (New in version 0.3.0)

  • get_localized_description

    Return localized or non-localized description. (New in version 0.3.0)

  • localize

    Return an Argument with localized attributes (New in version 0.3.0)

Source code in src\helply\types\argument.py
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
@dataclass
class Argument:
    """Represents a SlashCommand argument.

    Attributes
    ----------
    name: str
        Argument's non-localized name
    description: str
        Argument's non-localized description
    required: bool
        Whether or not the argument is required.
    name_localizations: disnake.LocalizationValue
        Contains localizations for the argument's name. (*New in version 0.3.0*)
    description_localizations: disnake.LocalizationValue
        Contains localizations for the argument's description. (*New in version 0.3.0*)

    Methods
    -------
    get_localized_name(locale: disnake.Locale)
        Return localized or non-localized name. (*New in version 0.3.0*)
    get_localized_description(locale: disnake.Locale)
        Return localized or non-localized description. (*New in version 0.3.0*)
    localize(locale: disnake.Locale)
        Return an Argument with localized attributes (*New in version 0.3.0*)
    """

    name: str
    description: str
    required: bool
    name_localizations: LocalizationValue
    description_localizations: LocalizationValue

    def get_localized_name(self, locale: Locale) -> str:
        """Return localized or non-localized name. specified by the provided locale.

        If not available, return the non-localized name instead.

        Parameters
        ----------
        locale: disnake.Local
            The interaction locale

        Returns
        -------
        str
            The localized or non-localized name.
        """
        if not self.name_localizations or not self.name_localizations.data:
            return self.name

        return self.name_localizations.data.get(str(locale), self.name)

    def get_localized_description(self, locale: Locale) -> str:
        """Return localized or non-localized description. specified by the provided locale.

        If not available, return the non-localized description instead.

        Parameters
        ----------
        locale: disnake.Local
            The interaction locale

        Returns
        -------
        str
            The localized or non-localized description.
        """
        if not self.description_localizations or not self.description_localizations.data:
            return self.name

        return self.description_localizations.data.get(str(locale), self.description)

    def localize(self, locale: Locale) -> Argument:
        """Return a Argument instance with localized name and description.

        Parameters
        ----------
        locale: disnake.Locale
            The locale that should be used to localize the argument.

        Returns
        -------
        Argument
            This argument with localized name and description
        """
        return Argument(
            name=self.get_localized_name(locale),
            description=self.get_localized_description(locale),
            required=self.required,
            name_localizations=self.name_localizations,
            description_localizations=self.description_localizations,
        )

get_localized_description(locale)

Return localized or non-localized description. specified by the provided locale.

If not available, return the non-localized description instead.

Parameters:

  • locale (Locale) –

    The interaction locale

Returns:

  • str

    The localized or non-localized description.

Source code in src\helply\types\argument.py
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
def get_localized_description(self, locale: Locale) -> str:
    """Return localized or non-localized description. specified by the provided locale.

    If not available, return the non-localized description instead.

    Parameters
    ----------
    locale: disnake.Local
        The interaction locale

    Returns
    -------
    str
        The localized or non-localized description.
    """
    if not self.description_localizations or not self.description_localizations.data:
        return self.name

    return self.description_localizations.data.get(str(locale), self.description)

get_localized_name(locale)

Return localized or non-localized name. specified by the provided locale.

If not available, return the non-localized name instead.

Parameters:

  • locale (Locale) –

    The interaction locale

Returns:

  • str

    The localized or non-localized name.

Source code in src\helply\types\argument.py
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
def get_localized_name(self, locale: Locale) -> str:
    """Return localized or non-localized name. specified by the provided locale.

    If not available, return the non-localized name instead.

    Parameters
    ----------
    locale: disnake.Local
        The interaction locale

    Returns
    -------
    str
        The localized or non-localized name.
    """
    if not self.name_localizations or not self.name_localizations.data:
        return self.name

    return self.name_localizations.data.get(str(locale), self.name)

localize(locale)

Return a Argument instance with localized name and description.

Parameters:

  • locale (Locale) –

    The locale that should be used to localize the argument.

Returns:

  • Argument

    This argument with localized name and description

Source code in src\helply\types\argument.py
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
def localize(self, locale: Locale) -> Argument:
    """Return a Argument instance with localized name and description.

    Parameters
    ----------
    locale: disnake.Locale
        The locale that should be used to localize the argument.

    Returns
    -------
    Argument
        This argument with localized name and description
    """
    return Argument(
        name=self.get_localized_name(locale),
        description=self.get_localized_description(locale),
        required=self.required,
        name_localizations=self.name_localizations,
        description_localizations=self.description_localizations,
    )