Discord.py bot that assigns an existing active role to users who posted in the target server within the last 14 days.
Activity is detected from messages in:
- Text channels
- Voice channel text chats
The bot runs once immediately after startup and exits normally after processing finishes. Run it every day at midnight with GitHub Actions or another scheduler.
- Replace the placeholders in
main.py:TARGET_GUILD_IDACTIVE_ROLE_ID
- Set the bot token as an environment variable. For GitHub Actions, store it
as a repository secret and pass it through
env.
export DISCORD_TOKEN='your-bot-token'- Run the bot:
uv run python main.pyThe bot intentionally does not write progress logs, counts, channel names, user IDs, role IDs, or exception details to stdout/stderr.
uv run ruff format --check .
uv run ruff check .
uv run ty check .
pnpm run format:checkThe workflow is defined in .github/workflows/active-role.yml.
CI checks are defined in .github/workflows/ci.yml.
Set this repository secret:
DISCORD_TOKEN: Discord bot token
The workflow runs at 00:00 JST every day. GitHub Actions schedules are written
in UTC, so the cron expression is 0 15 * * *.
You can also run it manually from the Actions tab with workflow_dispatch.
The bot needs:
- Server Members Intent enabled in the Discord Developer Portal
- Permission to view channels and read message history
- Permission to manage roles
- The bot role must be higher than the active role in the server role hierarchy
The active role must already exist. This bot intentionally does not create a
fallback role when ACTIVE_ROLE_ID is missing.