Bot commands, events and methods (Voxnup Bot Manager v2)
Bot commands are defined with this.command(name, options, handler) and used in chat as /botname:command (or this.prefix + command); /botname:yardim lists them automatically. For events, define methods such as onMessage and onReady, or use this.on("message", fn). Message, status, voice, moderation, storage, HTTP and timer methods live on this. Bot code runs in a sandbox with no file, OS or local network access.
Chat commands
Users type /botname:command arguments. If you set this.prefix = "!", !command works too. Handlers can be async. Commands not defined with this.command go to the onCommand(command, args, roomKey, channelKey, user) method.
| Option | Meaning |
|---|---|
description, usage | Shown in the automatic help list (/botname:yardim) |
aliases | Other names, e.g. ["z"] |
cooldown | Per-user cooldown (seconds) |
ownerOnly | Only the owners in the .json file |
minArgs | Fewer arguments returns "Usage: ..." |
allow(ctx) | Returning false rejects the command |
hidden | Hide from the help list |
Slash commands
Give a command options (or slash: true) and the bot registers it in the / menu when it connects; users pick the command and fill in the options from pickers. The command reaches the bot as an interaction, not a message, and the same handler runs: ctx.isInteraction, ctx.options, ctx.get("user"), ctx.reply(text, { ephemeral: true }), ctx.defer(). The bot must reply or defer within 3 seconds; Bot Manager defers on its own after 2 seconds. Details: developer.voxnup.com. User side: Slash commands.
The handler receives ctx: command, args (a quoted phrase counts as one argument), rawArgs, user, roomKey, channelKey, message, reply(text).
Events
| Event | Parameters / when |
|---|---|
onReady | { reconnected, user }: when the connection and session are ready |
onMessage | text, user, roomKey, channelKey, msg: messages that aren't commands (the bot's own messages are skipped) |
onMessageEdited / onMessageDeleted | msg / { messageId, roomKey } |
onSendFailed | { roomKey, reason, waitSeconds }: slow mode or timeout |
onTyping | { roomKey, userKey, nickname } |
onVoiceRoomJoin / onVoiceRoomLeave | roomKey, channelKey, user |
onJoinedVoiceRoom, onJoinRoomFailed, onMoved, onKicked | The bot's own voice room events |
onChannelJoin, onChannelUpdated | Channel events |
onFriendRequest, onFriendAccepted | user |
onGroupJoined, onGroupRemoved, onGroupMembersChanged, onGroupUpdated | { roomKey } |
onPresence | { userKey, status, statusText, presence } |
onServerError | { action, message }: the server rejected a request |
onDisconnected / onReconnected | Connection lost / restored |
onRawEvent | operation, data, event: every event from the server |
onError | error, where: every uncaught error |
onStop | When the bot is being stopped |
Methods
| Group | Methods |
|---|---|
| Messages | sendMessage(text, roomKey) (Promise: { messageKey, roomKey }), sendDirectMessage(userKey, text), editMessage(messageKey, text, roomKey), deleteMessage(messageKey), startTyping(roomKey) / stopTyping(roomKey) |
| Status | setStatus(0..5), setPresence(text, { elapsed, iconUrl }), clearPresence() |
| Queries (Promise) | getRoomUsers(roomKey), getOnlineFriends(), findUserVoiceRoom(userKey) |
| Voice and moderation | joinRoom / leaveRoom, moveUser(userKey, targetRoomKey), deafenUser(roomKey, userKey, on?), kickFromRoom(roomKey, userKey) |
| Storage | getState(key, file?), setState(key, value, saveNow?, file?), deleteState, stateKeys, clearStateFile, saveState |
| HTTP | await this.fetch(url, { method, headers, body, auth }) → { ok, status, headers, text, json, error } |
| Timers | setTimeout, setInterval, clearTimeout, clearInterval, this.every(ms, fn), this.after(ms, fn), this.cancel(id) |
Moderation only works in channel rooms: the bot's role needs the matching permission (Move Members, Deafen Members) and the bot must rank above its target. A bot can't send audio, and if it sits idle in a voice room it may count as inactive. Storage lives in states/<bot>/<file>.json and is saved once a minute and on shutdown.
Sandbox and limits
| Setting (appsettings.json) | Default | Note |
|---|---|---|
Sandbox.TimeoutMs | 5000 | Time limit for a single event handler; if exceeded the handler is stopped and the bot keeps running |
Sandbox.MemoryLimitMb | 128 | |
RateLimit | 5 messages per 5 s | Extra messages are queued (up to 50), then dropped |
Fetch.TimeoutSeconds / MaxResponseKb | 15 / 2048 | |
Fetch.BlockPrivateNetworks | true | Bots can't reach the local network (localhost, 192.168.x…) |
Frequently asked questions
Why don't my bot's commands work?
Commands must be written as /botname:command (or with your prefix). The bot must be in that channel and have Send Messages there. Use bot status to check it's connected and bot logs <name> for errors.
Why does my bot get a "slow mode" error?
If slow mode is on in the room, the bot follows it too; onSendFailed fires with reason: "slow_mode" and the wait time. A bot also sends at most 5 messages per 5 seconds; the rest are queued.