mirror of
https://github.com/Paillat-dev/discord-progress-bar.git
synced 2026-01-02 01:06:18 +00:00
First Commit
This commit is contained in:
40
examples/basic.py
Normal file
40
examples/basic.py
Normal file
@@ -0,0 +1,40 @@
|
||||
# Copyright (c) Paillat-dev
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
import os
|
||||
|
||||
import discord
|
||||
from dotenv import load_dotenv
|
||||
|
||||
from discord_progress_bar import ProgressBar, ProgressBarManager
|
||||
|
||||
# Load environment variables from .env file
|
||||
load_dotenv()
|
||||
|
||||
bot = discord.Bot(cache_app_emojis=True)
|
||||
|
||||
|
||||
class MyCog(discord.Cog):
|
||||
def __init__(self, bot: discord.Bot) -> None:
|
||||
self.bot: discord.Bot = bot
|
||||
self.progress_bar_manager: ProgressBarManager
|
||||
self.progress_bar: ProgressBar
|
||||
|
||||
@discord.Cog.listener()
|
||||
async def on_ready(self) -> None:
|
||||
print(f"Logged in as {bot.user} (ID: {bot.user.id})")
|
||||
print("------")
|
||||
self.progress_bar_manager = await ProgressBarManager(self.bot)
|
||||
self.progress_bar = await self.progress_bar_manager.progress_bar("green", length=10)
|
||||
print("Progress bar manager loaded.")
|
||||
|
||||
@discord.slash_command()
|
||||
async def get_progress_bar(self, ctx: discord.ApplicationContext, percent: float | None = None) -> None:
|
||||
"""Send a progress bar message."""
|
||||
if percent is None:
|
||||
percent = 1
|
||||
await ctx.respond(f"Progress: {self.progress_bar.partial(percent)}")
|
||||
|
||||
|
||||
bot.add_cog(MyCog(bot))
|
||||
bot.run(os.environ["DISCORD_TOKEN"])
|
||||
Reference in New Issue
Block a user