or run

tessl search
Log in

Version

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/py-cord@2.6.x
tile.json

tessl/pypi-py-cord

tessl install tessl/pypi-py-cord@2.6.0

A modern, async-ready Python API wrapper for Discord with comprehensive bot development features

Agent Success

Agent success rate when using this tile

93%

Improvement

Agent success rate improvement when using this tile compared to baseline

1.11x

Baseline

Agent success rate without this tile

84%

task.mdevals/scenario-10/

Discord Bot Manager

A Discord bot manager that provides a robust connection handler for Discord bots with proper lifecycle management, connection state tracking, and intent configuration.

Capabilities

Bot Initialization and Configuration

Initialize a bot connection manager that handles Discord bot instances with proper intent configuration and connection parameters.

  • Creating a bot manager with default intents (guilds, guild_messages, message_content) initializes successfully and stores configuration @test
  • Creating a bot manager with custom intents (only guilds and guild_members) initializes with those specific intents @test
  • Creating a bot manager with an empty token raises a ValueError @test

Connection State Management

Manage the bot's connection state throughout its lifecycle, providing clear status information.

  • After initialization, the bot manager reports connection state as "disconnected" @test
  • After starting the connection process, the connection state transitions through "connecting" to "connected" when ready @test
  • After calling disconnect, the connection state changes to "disconnected" @test

Event Handler Registration

Provide a mechanism to register custom event handlers for Discord events without replacing the default handlers.

  • Registering a handler for the "on_ready" event allows the handler to be called when the bot connects @test
  • Registering multiple handlers for the same event calls all handlers when the event occurs @test
  • Attempting to register a non-callable as a handler raises a TypeError @test

Graceful Shutdown

Implement proper cleanup and shutdown procedures for the bot connection.

  • Calling shutdown when connected properly closes the connection and cleans up resources @test
  • Calling shutdown when already disconnected completes without errors @test
  • After shutdown, attempting to connect again with the same manager instance succeeds @test

Implementation

@generates

API

from typing import Optional, Callable, Any
from enum import Enum

class ConnectionState(Enum):
    """Represents the connection state of the bot."""
    DISCONNECTED = "disconnected"
    CONNECTING = "connecting"
    CONNECTED = "connected"

class BotManager:
    """
    Manages a Discord bot connection with lifecycle tracking and event handling.

    This class wraps Discord bot functionality to provide connection state management,
    event handler registration, and graceful shutdown capabilities.
    """

    def __init__(self, token: str, intents: Optional[Any] = None):
        """
        Initialize the bot manager.

        Args:
            token: The Discord bot token for authentication
            intents: Optional Discord Intents object. If None, uses default intents
                    (guilds, guild_messages, message_content)

        Raises:
            ValueError: If token is empty or None
        """
        pass

    def get_connection_state(self) -> ConnectionState:
        """
        Get the current connection state of the bot.

        Returns:
            ConnectionState: The current connection state
        """
        pass

    async def connect(self) -> None:
        """
        Connect the bot to Discord.

        This method initiates the connection process. The connection state will
        transition from DISCONNECTED to CONNECTING, and eventually to CONNECTED
        when the ready event fires.
        """
        pass

    def register_event_handler(self, event_name: str, handler: Callable) -> None:
        """
        Register a custom event handler for a Discord event.

        Multiple handlers can be registered for the same event. All registered
        handlers will be called when the event occurs.

        Args:
            event_name: The name of the event (e.g., "on_ready", "on_message")
            handler: A callable that will be invoked when the event occurs

        Raises:
            TypeError: If handler is not callable
        """
        pass

    async def disconnect(self) -> None:
        """
        Disconnect the bot from Discord.

        This method closes the connection gracefully and transitions the
        connection state to DISCONNECTED.
        """
        pass

    async def shutdown(self) -> None:
        """
        Perform a graceful shutdown of the bot manager.

        This ensures proper cleanup of resources and connection closure.
        Can be called multiple times safely.
        """
        pass

    def get_bot_instance(self) -> Any:
        """
        Get the underlying Discord bot instance.

        Returns:
            The Discord Bot object managed by this manager
        """
        pass

Dependencies { .dependencies }

py-cord { .dependency }

Provides Discord API integration for Python, including Bot and Client classes, Intent system, and event handling capabilities.

@satisfied-by