The root README carried the full ten cog manual while the wiki held the authoritative pages. Point the repository at the wiki, keep only install and catalog basics in the README, and remove the per cog documents that are now folded into wiki source under wiki/.
3.9 KiB
ImageGrab
Collects every image in a channel and uploads them as one or more zip files. The naming scheme supports a workflow where message text acts as a tag list for the images attached to that message.
Requirements
- The invoking member needs Manage Messages.
- The bot needs Attach Files and Read Message History in the channel it scans and in the channel where it replies.
- No configuration and no stored data.
Command
[p]imagegrab [channel] [limit]
| Argument | Meaning |
|---|---|
channel |
Text channel to scan. Defaults to the current channel |
limit |
Maximum number of messages to scan, counted from the oldest message forward. Omit to scan the entire history |
The command is not guild only, but Discord resolves the channel argument only inside a guild.
What counts as an image
Attachments whose filename ends with one of .png, .jpg, .jpeg, .gif, .webp, .bmp, .tiff. The check is on the filename extension, not the content type.
Embedded images are included when the embed type is image and the embed URL, with any query string removed, ends in one of those extensions. Tenor and other services that serve extensionless URLs are skipped.
Videos, audio and files without those extensions are ignored.
Naming rules
Message text becomes the filename base, which is why the description mentions WebTable card decks and type tags.
- Characters removed:
<,>,:,",/,\,|,?,*, and the null character. - Runs of whitespace collapse to single spaces.
- The base is truncated to 200 characters.
- Commas, spaces, hyphens and underscores survive.
- One image in a message:
<base><ext>. - Several images in a message:
<base>_1<ext>,<base>_2<ext>, and so on. - No message text:
<message id><ext>.
Two messages with identical text produce identical filenames in the zip. zipfile allows duplicate entries; extraction tools may overwrite or rename them.
Embedded images with no message text also use the message ID, so an embed and an attachment on the same message can collide on extension only if their extensions match.
How it works
- The bot posts a status message and edits it as work proceeds.
channel.history(limit=limit, oldest_first=True)walks the channel from oldest to newest.- Every 2000 messages scanned, the status message is edited to show the count and the number of images found so far.
- Image URLs are collected without downloading.
- Each URL is downloaded in sequence through one shared
aiohttpsession. A non-200 response or an exception increments the failure count. - If every download fails, the status becomes "All image downloads failed." and nothing is sent.
- Downloaded bytes are written into zip archives, cutting a new archive when adding the next file would push the uncompressed byte count past 9 MiB.
- Each archive is uploaded as
<channel>_images.zip, or<channel>_images_part1.zip,_part2.zipand so on when there is more than one.
Limits and failure modes
- Everything is held in memory. A channel with thousands of large images can exhaust the bot's memory before the first zip is built.
- The 9 MiB cutoff uses raw file sizes, not the compressed archive size, and does not account for zip headers. It leaves headroom under Discord's 10 MiB default upload limit.
- A single image larger than 9 MiB goes into its own archive, which can exceed the upload limit and fail at upload time.
- There is no per-image size cap and no retry. A transient CDN error counts as a failed download.
- The scan is sequential, so a very large channel takes a long time and the status message edits are the only feedback.
- History scanning requires the bot to be able to read messages that predate its permissions. Messages it cannot read are simply absent.
Output
The final status message reports how many images were downloaded, the channel name, the number of archives, and the failure count when non-zero. Multi-part uploads also get a caption on each message identifying the part number.