Examples
Choose the example that matches the application you want to build. Set your token as described in Installation before running any example.
Standalone applications
Your first request — look up an item and read its market value.
Use several resources together — read daily gifts, find related items, check sales, and inspect the latest lottery result and streaming game.
Watch drops without a Discord bot — keep a client open and receive drop notifications.
Standalone recipes — complete catalog, relationship, cache-refresh, and pagination recipes.
Discord bots
Functions and decorators — use commands and listeners defined as functions.
A Bot subclass — let a Bot subclass own client startup and shutdown.
Using Cogs — put commands and notifications in a reloadable Cog.
Item autocomplete — suggest item names in a slash command.
Slash command recipes — several ready-to-load command Cogs with practical lookups.
Discord notifications — separate command and notification Cogs sharing one client.
Persistent Discord notifications — a persistent Discord launcher using SQLite or PostgreSQL.
Configuration and delivery
Caching and changing values — change item caching and refresh values on demand.
Which requests run — choose how often subscribed resources are polled.
Client lifecycle and requests — control client startup, timeouts, and logging.
Persistent event delivery — preserve detected callbacks with SQLite or PostgreSQL.
Shared workers — share polling across processes.
Use several resources together
Save this as launcher.py and run python launcher.py:
import asyncio
import os
from dankmemer import DankMemer
async def main() -> None:
async with DankMemer(os.environ["DANK_MEMER_API_TOKEN"]) as dank:
item = await dank.items.get("Life Saver")
if item is not None:
print(f"{item.name}: market value {item.market_value:,}")
for sale in await dank.store_sales.for_item(item):
print(f"On sale for {sale.price:g}: {sale.url}")
for gift in await dank.store_daily_gifts.today():
print(f"{gift.category}: {gift.metadata.render}")
reward_item = await dank.store_daily_gifts.reward_item(gift)
if reward_item is not None:
print(f"Item reward: {reward_item.name}")
result = await dank.lottery.latest()
if result is not None:
print(f"Latest lottery: {result.drawn_at}, winnings {result.winnings:,}")
print(f"Trending game: {await dank.stream.trending_game()}")
if __name__ == "__main__":
asyncio.run(main())
The item lookup and gift reward helper share the item catalog cache. Live resources are requested when you call their methods. The client closes after the program finishes.
Watch drops without a Discord bot
The Events and polling guide includes a complete drop notifier, its polling schedule, and how to include drops already available at startup. Every callback is documented in Event reference.