Simple
Simple integration, let random-memes cook
Get a random meme from Lemmy in one call or one command. No API key, zero dependencies.
random-memes is a Node.js package that picks a random image post from Lemmy meme communities and returns its image URL, caption, community and post link. Use it to add memes to a Discord or Telegram bot, a web page or a terminal script. To call it from other languages, see how to serve it as your own meme API.
import { random } from "random-memes";
const { image, caption } = await random();Each call to random() resolves to a plain object with four fields: image, a direct link to a JPEG, PNG, GIF or WebP file; caption, the post title; category, the Lemmy community the post came from; and permalink, a link to the original post. That is enough to post the image in a chat, show it on a page or credit the source.
The package reads the hot posts of three Lemmy meme communities through Lemmy's public API, using the fetch built into Node.js. It drops pinned, NSFW, removed and non-image posts, merges cross-posts that share an image, and keeps the result in memory for 10 minutes. Calls in that window pick from the cached list without sending new requests, so a busy bot does not flood the Lemmy instances. If one community is down, the other two are still used.
There is no hosted server between you and Lemmy and nothing to sign up for. Your process talks to the instances directly.
The package ships its own TypeScript declarations and works with both require and named ES module imports.