我的机器人有很多齿轮,但我使用命令加载和卸载它们
我仍然感到困惑,一次又一次地装卸齿轮。
我想知道有没有一种方法可以使用命令检查所有加载和卸载的齿轮。(除了默认的help命令)
发布于 2020-07-23 01:30:24
查看discord.py documentation,如果您尝试加载已加载的齿轮,它将引发discord.ext.commands.ExtensionAlreadyLoaded异常。使用此错误,您可以执行以下操作:
from discord import commands
bot = commands.Bot(command_prefix="!")
@bot.command()
async def check_cogs(ctx, cog_name):
try:
bot.load_extension(f"cogs.{cog_name}")
except commands.ExtensionAlreadyLoaded:
await ctx.send("Cog is loaded")
except commands.ExtensionNotFound:
await ctx.send("Cog not found")
else:
await ctx.send("Cog is unloaded")
bot.unload_extension(f"cogs.{cog_name}")附言:您的齿轮将需要在一个cogs文件夹中,这段代码才能工作。
https://stackoverflow.com/questions/63036583
复制相似问题