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:
15
README.md
15
README.md
@@ -79,17 +79,24 @@ 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
|
||||||
bot.run("YOUR_TOKEN")
|
bot.run("YOUR_TOKEN")
|
||||||
|
|||||||
Reference in New Issue
Block a user