Admin posts a message, configures the role+emoji pair, and any user who reacts gets the role. Reaction events carry custom emoji as their bare name, so normalize the stored form before comparing. Needs events:message_content: without it the default privacy mode strips emoji and user_bot from reaction events.
from yourbot_sdk import Plugin, Context
from yourbot_sdk.events import ReactionAdd
plugin = Plugin()
@plugin.on_event("reaction_add")
def grant_role(ctx: Context, event: ReactionAdd):
if event.get("user_bot"):
return # ignore bot reactions, including our own
cfg = ctx.kv.get(f"react_role:{event['message_id']}")
if not cfg:
return
want = cfg["emoji"]
if want.startswith("<"): # "<:pepega:1234>" -> "pepega"
want = want.split(":")[1]
if event["emoji"] == want:
ctx.discord.add_role(user_id=event["user_id"], role_id=cfg["role_id"])
@plugin.on_slash_command("react-role-bind")
def bind(ctx: Context, event: dict):
opts = {o["name"]: o["value"] for o in event.get("options", [])}
ctx.kv.set(f"react_role:{opts['message_id']}",
{"emoji": opts["emoji"], "role_id": opts["role"]})
ctx.interaction.respond(content="Reaction role bound.")
plugin.run()