Refactor progress bar setup and improve event handling.

Moved ProgressBarManager initialization to the `on_ready` event for better encapsulation. Updated `show_progress` to include a concise docstring and ensure consistent functionality.
This commit is contained in:
2025-04-23 18:27:03 +02:00
parent a2b376c49f
commit a1d49f9648

View File

@@ -79,16 +79,23 @@ from discord_progress_bar import ProgressBarManager
# Create a Discord bot with emoji caching enabled # Create a Discord bot with emoji caching enabled
bot = discord.Bot(cache_app_emojis=True) bot = discord.Bot(cache_app_emojis=True)
progress_bar_manager = None
progress_bar = None
@bot.event @bot.event
async def on_ready(): async def on_ready():
"""Initialize the ProgressBarManager when the bot is ready."""
global progress_bar_manager, progress_bar
# Initialize the progress bar manager # Initialize the progress bar manager
progress_bar_manager = await ProgressBarManager(bot) progress_bar_manager = await ProgressBarManager(bot)
# Get a progress bar with the "green" style # Get a progress bar with the "green" style
progress_bar = await progress_bar_manager.progress_bar("green") progress_bar = await progress_bar_manager.progress_bar("green")
# Use it in your commands @bot.slash_command()
@bot.slash_command() async def show_progress(ctx, percent: float = 0.5):
async def show_progress(ctx, percent: float = 0.5): """Display a progress bar with the specified percentage."""
await ctx.respond(f"Progress: {progress_bar.partial(percent)}") await ctx.respond(f"Progress: {progress_bar.partial(percent)}")
# Run your bot # Run your bot