Documentación / Developers / Cookbook / 6) Custom commands stored in KV
BuildSDK 0.10.1

6) Custom commands stored in KV

These docs are public. To publish a plugin you need a YourBot account: sign in to open the Dev Portal.

Server admins add their own !shortcut commands without redeploying.

from yourbot_sdk.events import MessageCreate

@plugin.on_event("message_create")
def custom(ctx: Context, event: MessageCreate):
    content = event.get("content", "").strip()
    if not content.startswith("!"):
        return
    name = content[1:].split(" ", 1)[0]
    response = ctx.kv.get(f"cmd:{name}")
    if response:
        ctx.discord.send_message(channel_id=event["channel_id"], content=str(response))

@plugin.on_slash_command("addcmd")
def add(ctx: Context, event: dict):
    opts = {o["name"]: o["value"] for o in event.get("options", [])}
    ctx.kv.set(f"cmd:{opts['name']}", opts["response"])
    ctx.interaction.respond(content=f"Saved !{opts['name']}.")
YourBot docs Reference tables are generated from the code that is running. Ask in Discord Suggest a correction