mirror of
https://github.com/Paillat-dev/discord-progress-bar.git
synced 2026-01-02 01:06:18 +00:00
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:
13
README.md
13
README.md
@@ -79,16 +79,23 @@ from discord_progress_bar import ProgressBarManager
|
||||
# Create a Discord bot with emoji caching enabled
|
||||
bot = discord.Bot(cache_app_emojis=True)
|
||||
|
||||
progress_bar_manager = None
|
||||
progress_bar = None
|
||||
|
||||
@bot.event
|
||||
async def on_ready():
|
||||
"""Initialize the ProgressBarManager when the bot is ready."""
|
||||
global progress_bar_manager, progress_bar
|
||||
|
||||
# Initialize the progress bar manager
|
||||
progress_bar_manager = await ProgressBarManager(bot)
|
||||
# Get a progress bar with the "green" style
|
||||
progress_bar = await progress_bar_manager.progress_bar("green")
|
||||
|
||||
# Use it in your commands
|
||||
@bot.slash_command()
|
||||
async def show_progress(ctx, percent: float = 0.5):
|
||||
@bot.slash_command()
|
||||
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)}")
|
||||
|
||||
# Run your bot
|
||||
|
||||
Reference in New Issue
Block a user