我们从Python开源项目中,提取了以下4个代码示例,用于说明如何使用discord.LoginFailure()。
def run(self, token): """ Override's discord.py's function for running the bot """ try: super().run(token, bot=(not self.config.selfbot)) except discord.LoginFailure: log.critical("Incorrect login token") if not self.config.selfbot: log.critical( "Using your own token? Change 'selfbot' to 'True' in the config") else: log.critical( "Using an OAuth account? Change 'selfbot' to 'False' in the config") except discord.HTTPException as e: log.critical(e)
def main(loop=None): if loop is None: loop = asyncio.get_event_loop() bot = Bot(loop=loop, command_prefix=core.get_prefixes(), description=__doc__, pm_help=core.is_help_private()) if not is_configured(): initial_config() error = False error_message = "" try: loop.run_until_complete(run(bot)) except discord.LoginFailure: error = True error_message = 'Invalid credentials' choice = input(strings.invalid_credentials) if choice.strip() == 'reset': base.delete_token() else: base.disable_restarting() except KeyboardInterrupt: base.disable_restarting() loop.run_until_complete(bot.logout()) except Exception as e: error = True print(e) error_message = traceback.format_exc() base.disable_restarting() loop.run_until_complete(bot.logout()) finally: if error: print(error_message) return bot
def run(self): try: self.log.info('Connecting to Discord Gateway...') super().run(self.cfg.dsc.token, bot=self.cfg.dsc.bot) except discord.LoginFailure: self.log.error('Invalid Token!') exit(errno.EPERM)
def runbot(self): try: if (self.user and self.passwd) and not self.token: await self.client.start(self.user, self.passwd, bot=False) elif self.token and not (self.user or self.passwd): await self.client.start(self.token, bot=self.botAccount) except discord.LoginFailure: self.openAuth(f=True) save_auth((self.user, self.passwd, self.token, self.botAccount,)) finally: await self.runbot()