Kharat Bot Docs

KAL triggers & context

WHEN COMMAND, WHEN EVENT, WHEN INTERACTION and SCHEDULE — the complete event list and every context variable each trigger provides.

A trigger declares when a block of KAL runs. There are four kinds, and each provides a strictly-defined set of context variables — using a variable a trigger does not provide is a compile error (S007), which keeps event handlers honest.

WHEN COMMAND#

kal
KAL VERSION 2.0;
AUTOMATION announcement_command {

    WHEN COMMAND announce (text AS STRING) [permission: "ManageMessages"] {
        SEND MESSAGE text TO channel;
    }
}
  • The command name is a bare identifier (not quoted). Parameters are declared (name AS TYPE, …) and are bound from the invocation.
  • The optional [permission: "…"] clause is checked against the calling member; a missing permission answers with exactly which permission was needed.
  • Context: interaction, member, author, channel, guild, options, data, config.
  • options.<name> mirrors the parameters; member.mention mentions the caller.

WHEN EVENT#

kal
KAL VERSION 2.0;
AUTOMATION join_logger {

    CONFIG {
        log_channel: CHANNEL [
            label: "Log channel",
            description: "Where joins are announced",
            required: true
        ];
    }

    WHEN EVENT member_join {
        SEND MESSAGE "Welcome, " + member.mention + "!" TO config.log_channel;
    }
}

The complete event list with the context each provides:

EventContext variables
message_sent, message_createmessage, channel, member, author, guild, data, config
message_deletedmessage, channel, guild, data, config
message_editedmessage, old_message, channel, member, author, guild, data, config
reaction_added, reaction_removedemoji, reaction_count, message, channel, member, guild, data, config
member_join, member_leavemember, guild, data, config — no channel
button_clickedinteraction, channel, member, guild, data, config
channel_created, channel_deletedchannel, guild, data, config
channel_updatedchannel, old_channel, guild, data, config
channel_pins_updatedchannel, guild, time, data, config
role_created, role_deletedrole, guild, data, config
role_updatedrole, old_role, guild, data, config
member_banneduser, member, guild, reason, data, config
member_unbanneduser, guild, data, config
thread_created, thread_deletedthread, channel, guild, data, config
thread_updatedthread, old_thread, channel, guild, data, config
voice_state_updatedmember, channel, old_channel, guild, voice_state, old_voice_state, data, config

WHEN INTERACTION#

Fires when a component (button/select) with the matching custom id is clicked. Custom ids are matched exactly.

kal
KAL VERSION 2.0;
AUTOMATION verify_panel {

    WHEN INTERACTION verify_button {
        REPLY "You have verified your account!" EPHEMERAL;
    }
}

Context: interaction, member, author, channel, guild, data, config, message. Acknowledge slow work with DEFER INTERACTION first (see Actions).

SCHEDULE#

kal
KAL VERSION 2.0;
AUTOMATION hourly_digest {

    CONFIG {
        target: CHANNEL [
            label: "Digest channel",
            description: "Where the digest is posted",
            required: true
        ];
    }

    SCHEDULE EVERY 3600000 {
        SEND MESSAGE "Hourly digest" TO config.target;
    }
}
  • SCHEDULE EVERY <ms> repeats; SCHEDULE AFTER "<duration>" runs once. Duration strings accept minutes/hours spellings such as "10m", "1h".
  • Context is deliberately small: guild, data, config only. There is no member or channel — targets come from CONFIG.
  • Scheduled bodies belong at the top level of the AUTOMATION block, next to WHEN blocks.

data and config#

Every trigger provides data (the event payload for this run) and config (the server's values for this script's CONFIG fields).