2016-11-18 52 views

回答

1

大概末到本问题,但我将它张贴反正

你应该怎么签所谓的“嵌齿轮”工作Discord.py。 The bot from Rapptz(主要维护Discord.py的人)有一些很好的例子,说明如何将你的机器人组织成Cogs以及如何加载/卸载/重新加载它们(参见cogs/admin.py)。

@commands.command(hidden=True) 
@checks.is_owner() 
async def load(self, *, module : str): 
    """Loads a module.""" 
    try: 
     self.bot.load_extension(module) 
    except Exception as e: 
     await self.bot.say('\N{PISTOL}') 
     await self.bot.say('{}: {}'.format(type(e).__name__, e)) 
    else: 
     await self.bot.say('\N{OK HAND SIGN}') 

@commands.command(hidden=True) 
@checks.is_owner() 
async def unload(self, *, module : str): 
    """Unloads a module.""" 
    try: 
     self.bot.unload_extension(module) 
    except Exception as e: 
     await self.bot.say('\N{PISTOL}') 
     await self.bot.say('{}: {}'.format(type(e).__name__, e)) 
    else: 
     await self.bot.say('\N{OK HAND SIGN}') 

@commands.command(name='reload', hidden=True) 
@checks.is_owner() 
async def _reload(self, *, module : str): 
    """Reloads a module.""" 
    try: 
     self.bot.unload_extension(module) 
     self.bot.load_extension(module) 
    except Exception as e: 
     await self.bot.say('\N{PISTOL}') 
     await self.bot.say('{}: {}'.format(type(e).__name__, e)) 
    else: 
     await self.bot.say('\N{OK HAND SIGN}') 

(​​)

相关问题