所以,这实际上是针对 revolt.chat 的 defeio python 库,但它们是非常相似的库,所以如果它是针对discord.py,我不需要帮助解释响应。
基本上,我正在寻找一种方法来显示加载齿轮所需的时间,并且在加载齿轮时在“正在加载管理齿轮”、“正在加载管理齿轮..”之间来回切换,并再次使用第三 ”。”直到它完成,然后最终在 {x} 秒内加载 {cogname} cog,对于每个 cog,这将很难像我现在所拥有的那样。
@commands.Cog.listener()
async def on_ready(self):
sys.stdout.write("\rLoading 'Administration' cog.")
await asyncio.sleep(1)
sys.stdout.write("\rLoading 'Administration' cog..")
await asyncio.sleep(1)
sys.stdout.write("\r'Administration' cog loaded..!")
sys.stdout.flush()
优选地,也可以选择(因为这是一个更高级的问题),我希望能够添加这个来加载每个齿轮,但我希望一旦加载所有齿轮就具有“所有齿轮在 {x} 秒内加载”
我的意思是我知道已经过去了 2 年,但如果有人正在寻找 discord.py 2.0 的解决方案,我发现它可以工作。用里面的 ping 命令作为测试
import discord
import asyncio
import time
import sys
from discord.ext import commands
class test(commands.Cog):
def __init__(self, bot):
self.bot = bot
@commands.Cog.listener()
async def on_ready(self):
cog_name = "PUT_CUSTOM_NAME_HERE"
start_time = time.time()
sys.stdout.write(f"\rloading '{cog_name}' cog.")
sys.stdout.flush()
await asyncio.sleep(1)
for i in range(3):
sys.stdout.write(f"\rloading '{cog_name}' cog{'.' * (i + 1)}")
sys.stdout.flush()
await asyncio.sleep(1)
end_time = time.time()
loading_time = end_time - start_time
sys.stdout.write(f"\'{cog_name}' cog loaded in {loading_time:.2f} seconds")
sys.stdout.flush()
@commands.command()
async def ping(self, ctx):
await ctx.send("pong")
async def setup(bot):
await bot.add_cog(test(bot))