Skip to content

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

discord-role-by-reaction

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.

Features

  • ✅ 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

Requirements

  • 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

Installation

git clone <this-repo>
cd discord-role-script
npm install

Configuration

Create 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=ADD

You 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 REMOVE

Note: environment-variable equivalents are DISCORD_TOKEN, DISCORD_SERVER_ID, DISCORD_CHANNEL_ID, DISCORD_MESSAGE_ID, DISCORD_ROLE_ID, and ACTION.

Usage

Grant the role to everyone who reacted to a poll:

node index.js --action ADD --message-id 1234 --channel-id 5678 --role-id 9012

Revoke the role from everyone who reacted:

node index.js --action REMOVE --message-id 1234 --channel-id 5678 --role-id 9012

Example output

[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.

How to get the IDs

  1. Server ID — right-click the server icon → Copy Server ID.
  2. Channel ID — right-click the channel → Copy Channel ID.
  3. Message ID — right-click the message → Copy Message ID.
  4. 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.

Creating a bot

  1. Go to the Discord Developer Portal → New Application.
  2. Go to the Bot tab → Reset Token / copy the token into DISCORD_TOKEN.
  3. Under Privileged Gateway Intents, enable:
    • Server Members Intent
    • Message Content Intent
  4. 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.

Permissions the bot needs

  • Manage Roles (to add/remove the target role)
  • Read Message History / View Channel (to fetch the message and its reactions)

License

MIT

About

CLI script to add/remove a Discord role for users who reacted to a message (or poll).

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages