Discord Bot Poller
Use this skill when an automation job needs to watch one Discord channel and react to new messages without a full gateway bot framework. The helper uses the Discord REST API, stores the last seen message id in memory or a caller-provided value, and honors rate-limit responses.
When to invoke
- User says: "poll a Discord channel", "trigger this from Discord", "watch messages and run a handler".
- The workflow needs a small single-channel inbox, not slash commands or real-time presence.
When NOT to invoke
- The user needs a full interactive bot; use
discord.pyand the Gateway instead. - The bot must receive messages instantly at high volume across many channels.
Concrete example
User input:
Poll my Discord alerts channel and send each new URL into the scraper.
Output:
# Copy assets/poller.py into your project, then:
from poller import poll_forever
def handle(message):
print(message["author"].get("username", "user"), message.get("content", ""))
poll_forever(handle, poll_seconds=5)
The helper reads DISCORD_BOT_TOKEN and DISCORD_CHANNEL_ID from env. Keep channel ids and tokens out of source control; persist last_message_id with [[sqlite-state]] if the poller must resume after restarts.
Pattern to apply
- Use a bot token from env and grant the bot access only to the channel it needs.
- Poll
GET /channels/{channel_id}/messageswithafter=last_message_idto avoid reprocessing. - Dispatch oldest-to-newest so handlers see messages in natural order.
- Honor HTTP 429
retry_afterandX-RateLimit-Reset-Afterbefore the next request. - Persist the last processed message id only after the handler succeeds.
Reference: assets/poller.py.
Source
Distilled from production use across the author's automation projects. v1.0.0. See also: [[sqlite-state]], [[telegram-alerter]], [[rate-limit-budget]].
→ Build the full runnable bot with Trawlkit.