Skip to content

Bot Recipes

SORA edited this page Nov 27, 2026 · 1 revision

One client per token

Make one Client per token and keep it around, don't build a new one for every message. The login, the account list and the cache get reused that way. login_file keeps the login across restarts too.

clients: dict[int, akef.Client] = {}


def client_for(user_id: int, token: str) -> akef.Client:
    if user_id not in clients:
        clients[user_id] = akef.Client(token, login_file=f"logins/{user_id}.json")
    return clients[user_id]

Close them when the bot shuts down: await client.close().

Tokens are full logins. If your bot stores them, store them like passwords, and only ever ask for them in DMs.

Sanity command (discord.py)

@tree.command(description="your sanity")
async def sanity(interaction: discord.Interaction):
    client = clients.get(interaction.user.id)
    if client is None:
        return await interaction.response.send_message("link your token first", ephemeral=True)
    try:
        card = await client.card()
    except akef.AuthError:
        return await interaction.response.send_message("your token expired, send a new one", ephemeral=True)
    s = card.stamina
    await interaction.response.send_message(f"sanity {s.current}/{s.max}")

Daily check-in for everyone

async def check_in_everyone():
    for user_id, client in clients.items():
        try:
            await client.check_in()
        except akef.AlreadyCheckedIn:
            pass
        except akef.AuthError:
            ...  # tell that user to send a new token
        except akef.NetworkError:
            ...  # try again later

Run it once a day with whatever scheduler your bot uses, discord.ext.tasks.loop(time=...) in discord.py or a job queue in python-telegram-bot / aiogram.

Cards instead of text

akef-cards draws the same data as images, and has full discord.py and Telegram bot examples in its docs.

The snippets here aren't a whole bot, plug them into yours.

Clone this wiki locally