Skip to content

unban

User unbanning commands for Discord moderation.

This module provides functionality to unban users from Discord servers, with support for resolving users from ban lists using various identifiers.

Classes:

  • Unban

    Discord cog for unbanning users from servers.

Functions:

  • setup

    Set up the Unban cog.

Classes

Unban

Python
Unban(bot: Tux)

Bases: ModerationCogBase

Discord cog for unbanning users from servers.

Initialize the Unban cog.

Parameters:

  • bot (Tux) –

    The bot instance to attach this cog to.

Methods:

Attributes:

Attributes

db property

Get the database coordinator for accessing database controllers.

Returns:

  • DatabaseCoordinator

    Coordinator providing access to all database controllers.

Examples:

Python Console Session
>>> await self.db.guild_config.get_guild_config(guild_id)
>>> await self.db.cases.create_case(...)
Notes

This property provides convenient access to database operations without needing to access self.bot.db directly.

Functions

resolve_user_from_ban_list async
Python
resolve_user_from_ban_list(ctx: Context[Tux], identifier: str) -> User | None

Resolve a user from the ban list using username, ID, or partial info.

Parameters:

  • ctx (Context[Tux]) –

    The context of the command.

  • identifier (str) –

    The username, ID, or partial identifier to resolve.

Returns:

  • Optional[User]

    The user if found, None otherwise.

moderate_user async
Python
moderate_user(
    ctx: Context[Tux],
    case_type: CaseType,
    user: Member | User,
    reason: str,
    silent: bool = False,
    dm_action: str | None = None,
    actions: Sequence[tuple[Any, type[Any]]] | None = None,
    duration: int | None = None,
    **kwargs: Any,
) -> None

Execute moderation action using the service architecture.

Parameters:

  • ctx (Context[Tux]) –

    Command context

  • case_type (CaseType) –

    Type of moderation action

  • user (Member | User) –

    Target user

  • reason (str) –

    Reason for the action

  • silent (bool, default: False ) –

    Whether to suppress DM to user, by default False

  • dm_action (str | None, default: None ) –

    Custom DM action description, by default None

  • actions (Sequence[tuple[Any, type[Any]]] | None, default: None ) –

    Discord API actions to execute, by default None

  • duration (int | None, default: None ) –

    Duration in seconds for temporary actions, by default None

  • **kwargs (Any, default: {} ) –

    Additional case data

_setup_command_usage
Python
_setup_command_usage() -> None

Generate usage strings for all commands in this cog that lack explicit usage.

The generated usage follows the pattern: <qualified_name> <param tokens>

Where: - Required parameters are denoted as <name: Type> - Optional parameters are denoted as [name: Type] - The prefix is intentionally omitted (provided by ctx.prefix)

Examples:

ban <member: Member> [reason: str] config set <key: str> <value: str>

Notes

Respects explicit usage strings if already set on a command. Errors during generation are logged but don't prevent cog loading.

_perform_unban async
Python
_perform_unban(ctx: Context[Tux], user: User, final_reason: str, guild: Guild) -> None

Execute the core unban action and case creation.

unban async
Python
unban(
    ctx: Context[Tux],
    username_or_id: str,
    reason: str | None = None,
    *,
    flags: UnbanFlags,
) -> None

Unban a user from the server.

Parameters:

  • ctx (Context[Tux]) –

    The context object for the command.

  • username_or_id (str) –

    The username or ID of the user to unban.

  • reason (Optional[str], default: None ) –

    The reason for the unban.

  • flags (UnbanFlags) –

    The flags for the command.

is_jailed async
Python
is_jailed(guild_id: int, user_id: int) -> bool

Check if a user is jailed.

Parameters:

  • guild_id (int) –

    Guild ID to check

  • user_id (int) –

    User ID to check

Returns:

  • bool

    True if user is jailed, False otherwise

_generate_usage
Python
_generate_usage(command: Command[Any, ..., Any]) -> str

Generate a usage string with support for flags and positional parameters.

This method inspects the command's callback signature to detect: - FlagConverter parameters (e.g., --flag value) - Positional parameters (e.g., <required> or [optional])

Parameters:

  • command (Command) –

    The command to generate usage for.

Returns:

  • str

    Generated usage string, or qualified command name as fallback.

Notes

Delegates to shared usage generator for consistency across all cogs. Falls back gracefully to command name if generation fails.

is_pollbanned async
Python
is_pollbanned(guild_id: int, user_id: int) -> bool

Check if a user is poll banned.

Parameters:

  • guild_id (int) –

    Guild ID to check

  • user_id (int) –

    User ID to check

Returns:

  • bool

    True if user is poll banned, False otherwise

is_snippetbanned async
Python
is_snippetbanned(guild_id: int, user_id: int) -> bool

Check if a user is snippet banned.

Parameters:

  • guild_id (int) –

    Guild ID to check

  • user_id (int) –

    User ID to check

Returns:

  • bool

    True if user is snippet banned, False otherwise

get_config
Python
get_config(key: str, default: Any = None) -> Any

Get a configuration value from CONFIG with support for nested keys.

Parameters:

  • key (str) –

    The configuration key to retrieve. Supports dot notation for nested values (e.g., "BOT_INFO.BOT_NAME").

  • default (Any, default: None ) –

    Default value to return if key is not found, by default None.

Returns:

  • Any

    The configuration value or default if not found.

Examples:

Python Console Session
>>> self.get_config("BOT_INFO.BOT_NAME")
'Tux'
>>> self.get_config("MISSING_KEY", "fallback")
'fallback'
Notes

Errors during retrieval are logged but don't raise exceptions. Returns the default value on any error.

__repr__
Python
__repr__() -> str

Return a string representation of the cog instance.

Returns:

  • str

    String representation in format <CogName bot=BotUser>.

unload_if_missing_config
Python
unload_if_missing_config(condition: bool, config_name: str) -> bool

Check if required configuration is missing and log warning.

This allows cogs to detect missing configuration at load time and return early from init to prevent partial initialization.

Parameters:

  • condition (bool) –

    True if config is missing (should unload), False otherwise.

  • config_name (str) –

    Name of the missing configuration for logging purposes.

Returns:

  • bool

    True if config is missing (caller should return early), False if config is present.

Examples:

Python Console Session
>>> def __init__(self, bot: Tux):
...     super().__init__(bot)
...     if self.unload_if_missing_config(not CONFIG.GITHUB_TOKEN, "GITHUB_TOKEN"):
...         return  # Exit early, cog will be partially loaded but won't register commands
...     self.github_client = GitHubClient()
Notes

When this returns True, the cog's init should return early to avoid initializing services that depend on the missing config. The cog will be loaded but commands won't be registered properly, preventing runtime errors.

For complete cog unloading, the bot owner should remove the cog from the modules directory or use the reload system to unload it programmatically.

_unload_self async
Python
_unload_self(extension_name: str) -> None

Perform the actual cog unload operation.

Parameters:

  • extension_name (str) –

    Full extension name to unload.

Notes

This is called as a background task by unload_if_missing_config(). Errors during unload are logged but don't raise exceptions.

Functions

setup async

Python
setup(bot: Tux) -> None

Set up the Unban cog.

Parameters:

  • bot (Tux) –

    The bot instance to add the cog to.