What you will build
A /imagine slash command that takes a prompt and an optional character id, debits the wallet attached to your API key, and posts the resulting image in the channel once the job completes.
No chat completions are used — the API is image and video only.
Setup
Install discord.py 2.x and httpx. Register a Discord application, create a bot, copy its token.
Get a LovlyChat API key from developers@lovlychat.com bound to a prepaid LoveCoin wallet. Set DISCORD_TOKEN and LOVLY_API_KEY as env vars.
Core loop
On /imagine, POST to https://lovlychat.com/v1/generation/jobs with kind=image, variant=standard, prompt, and optional characterId. You get back a job id.
Poll GET /v1/generation/jobs/:id every 2 seconds with a hard cap (image jobs typically finish in 12 to 30 seconds on warm workers). When status is completed, send the asset URL back to the channel.
Handling 402
If POST /v1/generation/jobs returns 402, the wallet is empty. Reply in the channel with the current balance from the response and a link to top up.
Never silently retry — that is how you turn an empty wallet into a rate-limit ban.
Cost control patterns
Cache GET /v1/pricing once per hour and refuse jobs that would cost more than a per-user limit you set yourself.
Use GET /v1/wallet at startup and after every job to surface a live balance in your bot status.
よくある質問
Build a Discord Image-Generation Bot on the LovlyChat API explains Tutorial: a Discord slash command that generates an on-model character image via the LovlyChat prepaid API and posts it back in chat. It is written for users comparing AI companion products, evaluating relationship-style chat experiences, or looking for a clearer way to understand this topic before trying a platform.
This article is for people researching discord ai bot, comparing companion platforms, or trying to understand which product features make relationship-style AI chat feel more personal and worth returning to.
discord ai bot matters because users searching this topic often have stronger intent than broad chatbot traffic. They usually care about memory, personality, and continuity rather than only novelty or one-off responses.
Users can explore these ideas directly on lovlychat by browsing companions, creating a custom character, and opening persistent chat threads in the browser.