converters ¶
Discord.py command converters for Tux bot.
This module provides custom converters for parsing command arguments, including time durations, case types, and utility functions for channel resolution and boolean conversion.
Classes:
-
TimeConverter–Convert string representations of time durations to seconds.
-
CaseTypeConverter–Convert string representations to CaseType enum values.
Functions:
-
get_channel_safe–Get a TextChannel or Thread by ID, returning None if not found.
-
convert_bool–Convert a string to a boolean value.
Classes¶
TimeConverter ¶
Convert string representations of time durations to seconds.
Supports time units: s (seconds), m (minutes), h (hours), d (days). Examples: "1h30m", "2d", "45s", "1.5h".
Methods:
-
convert–Convert a string representation of time (e.g., "1h30m", "2d") into seconds.
Functions¶
convert async ¶
Convert a string representation of time (e.g., "1h30m", "2d") into seconds.
Parameters:
Returns:
-
float–The total time in seconds.
Raises:
-
BadArgument–If the time string format is invalid or uses invalid units.
CaseTypeConverter ¶
Convert string representations to CaseType enum values.
Accepts case type names (case-insensitive) and converts them to the corresponding CaseType enum value for moderation commands.
Methods:
-
convert–Convert a string to a CaseType enum.
Functions¶
convert async ¶
Convert a string to a CaseType enum.
Parameters:
-
ctx(Context[Any]) –The context to convert the argument to a CaseType enum.
-
argument(str) –The argument to convert to a CaseType enum.
Returns:
-
CaseType–The CaseType enum.
Raises:
-
BadArgument–If the argument is not a valid CaseType.
Functions¶
get_channel_safe async ¶
get_channel_safe(bot: Tux, channel_id: int) -> TextChannel | Thread | None
Get a TextChannel or Thread by ID, returning None if not found.
This narrows the return type so callers can safely use fetch_message and message.reactions.
Returns:
-
TextChannel | Thread | None–The channel if found and is a text channel or thread, None otherwise.