A simple, locally-run CLI script that adds or removes a Discord role for every user who reacted to a specific message (or voted on a poll message).
It is not a continuously running bot — it connects, performs the role change once, and exits.
- ✅ Add a role to everyone who reacted to a given message
- ✅ Remove a role from everyone who reacted to a given message
- ✅ Handles users who already have (or already lack) the role without crashing
- ✅ Skips bots automatically
- ✅ Logs every user who was added / removed / skipped
- ✅ Configuration via CLI flags or environment variables
- ✅ Clear per-user audit output and an end summary
- Node.js 18+
- A Discord bot token (see "Creating a bot" below)
- The bot must be a member of the target server with the Manage Roles permission
git clone <this-repo>
cd discord-role-script
npm installCreate a .env file (copy from .env.example):
DISCORD_TOKEN=your_bot_token_here
DISCORD_SERVER_ID=123456789012345678
DISCORD_CHANNEL_ID=123456789012345678
DISCORD_MESSAGE_ID=123456789012345678
DISCORD_ROLE_ID=123456789012345678
ACTION=ADDYou can also pass everything on the command line instead of (or overriding) the .env:
node index.js \
--token <bot token> \
--server-id <guild id> \
--channel-id <channel id> \
--message-id <message id> \
--role-id <role id> \
--action ADD # or REMOVENote: environment-variable equivalents are
DISCORD_TOKEN,DISCORD_SERVER_ID,DISCORD_CHANNEL_ID,DISCORD_MESSAGE_ID,DISCORD_ROLE_ID, andACTION.
Grant the role to everyone who reacted to a poll:
node index.js --action ADD --message-id 1234 --channel-id 5678 --role-id 9012Revoke the role from everyone who reacted:
node index.js --action REMOVE --message-id 1234 --channel-id 5678 --role-id 9012[INFO] Connecting… action=ADD guild=… message=… role=…
[INFO] Found 3 unique user(s) who reacted.
[ADD ] alice#0001
[ADD ] bob#0002
[SKIP ] carol#0003 already has the role.
[SUMMARY]
Added: 2
Removed: 0
Already had role: 1
No role to remove:0
Failed: 0
[DONE] Script finished.
- Server ID — right-click the server icon → Copy Server ID.
- Channel ID — right-click the channel → Copy Channel ID.
- Message ID — right-click the message → Copy Message ID.
- Role ID — Server Settings → Roles → right-click the role → Copy Role ID.
You must enable Discord Developer Mode (User Settings → Advanced → Developer Mode) to see the "Copy ID" options.
- Go to the Discord Developer Portal → New Application.
- Go to the Bot tab → Reset Token / copy the token into
DISCORD_TOKEN. - Under Privileged Gateway Intents, enable:
- Server Members Intent
- Message Content Intent
- Go to OAuth2 → URL Generator, select scopes
bot+applications.commands, and the permission Manage Roles, then open the generated URL to invite the bot to your server.
- Manage Roles (to add/remove the target role)
- Read Message History / View Channel (to fetch the message and its reactions)
MIT