tessl install tessl/pypi-py-cord@2.6.0A 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%
A Discord bot manager that provides a robust connection handler for Discord bots with proper lifecycle management, connection state tracking, and intent configuration.
Initialize a bot connection manager that handles Discord bot instances with proper intent configuration and connection parameters.
Manage the bot's connection state throughout its lifecycle, providing clear status information.
Provide a mechanism to register custom event handlers for Discord events without replacing the default handlers.
Implement proper cleanup and shutdown procedures for the bot connection.
@generates
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
"""
passProvides Discord API integration for Python, including Bot and Client classes, Intent system, and event handling capabilities.
@satisfied-by