Python discord 模块,LoginFailure() 实例源码
我们从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 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.token, self.botAccount,))
finally:
await self.runbot()
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。