# pull-messages-from-discord Pull messages from a Discord channel for the last N hours and save them as JSON. ## Setup Put the bot token in `.env` (gitignored): ``` HM_DISCORD_BOT_TOKEN=... ``` The bot needs View Channel + Read Message History on the channel, and the Message Content Intent enabled in the Developer Portal (otherwise `content` and `embeds` come back empty). ## Usage ``` uv run script.py --channel homelab-alerts --time 24h uv run script.py -c homelab-alerts -t 24 ``` Options: `-c/--channel` (required), `-t/--time` hours, `24` or `24h` (default 24), `-g/--guild` name or ID if the channel name is ambiguous, `-o/--output` file path. Output goes next to the script: `discord__.json`. ## jq examples ``` jq '.count' discord_homelab-alerts_*.json jq -r '.messages[] | "\(.timestamp) \(.content)"' file.json jq '.messages[].embeds[].title' file.json jq '.messages[] | select(.content | test("error"; "i"))' file.json ```