/afk <reason> sets the user's status; the bot replies when they're mentioned. Parsing mentions reads message text, so this recipe needs events:message_content.
import re
from yourbot_sdk.events import MessageCreate
@plugin.on_slash_command("afk")
def set_afk(ctx: Context, event: dict):
opts = {o["name"]: o["value"] for o in event.get("options", [])}
reason = opts.get("reason") or "afk"
ctx.kv.set(f"afk:{event['user_id']}", reason, ttl_seconds=86400)
ctx.interaction.respond(content=f"Got it, set you AFK ({reason}).")
@plugin.on_event("message_create")
def notify_mentions(ctx: Context, event: MessageCreate):
if event.get("author_bot"):
return
for uid in set(re.findall(r"<@!?(\d+)>", event.get("content", ""))):
reason = ctx.kv.get(f"afk:{uid}")
if reason:
ctx.discord.send_message(channel_id=event["channel_id"],
content=f"<@{uid}> is AFK: {reason}")