示例#1
0
async def run():
    bot = Bot(command_prefix=commands.when_mentioned_or(config.command_prefix))
    bot.remove_command("help")

    bot.pool = await asyncpg.create_pool(**config.postgres_login)
    bot.redis = await aioredis.create_pool("redis://localhost")
    bot.session = ClientSession()
    bot.config = config
    bot.started_at = datetime.datetime.now()

    try:
        for file in os.listdir("cogs"):
            if file.endswith(".py"):
                try:
                    bot.load_extension(f"cogs.{file[:-3]}")
                    print("successfully loaded cog", file[:-3])
                except Exception:
                    with open("error.log", "a+") as error_log:
                        error_log.write(
                            "#############################################\n")
                        traceback.print_exc(file=error_log)
                    error_log.close()
                    print(
                        f"# Error loading {file}! See error.log for more info."
                    )
        bot.load_extension("jishaku")
        await bot.start(config.token)
    except KeyboardInterrupt:
        await bot.logout()
示例#2
0
    except KeyError:
        return commands.when_mentioned_or(bot.config.global_prefix)(bot,
                                                                    message)
    return bot.config.global_prefix


bot = Bot(
    command_prefix=get_prefix,
    case_insensitive=True,
    description="The one and only IdleRPG bot for discord",
    shard_ids=loads(sys.argv[1]),
    shard_count=int(sys.argv[2]),
)
bot.version = config.version
bot.remove_command("help")
bot.config = config
bot.paginator = paginator
bot.BASE_URL = config.base_url

bot.linecount = 0

with open("idlerpg.py", encoding="utf-8") as f:
    bot.linecount += len(f.readlines())
for afile in os.listdir("cogs"):
    if os.path.isdir(afile) or not afile.endswith(".py"):
        continue
    with open(f"cogs/{afile}", "r", encoding="utf-8") as f:
        bot.linecount += len(f.readlines())


async def start_bot():