Skip to content
David edited this page Nov 7, 2020 · 1 revision

(WIP)

Creating an event handler

To create an event handler in your script, simply declare a sub-routine with "Event_" followed by the event name, for example to handle the "UserTalk" event you would declare:

Sub Event_UserTalk(Username, Flags, Message, Ping)
    If Message = "hello" Then
        AddQ "world!"
    End If
End Sub

With this example, whenever someone says "hello" in the channel, the bot will respond with "world!".

List of script events

Bot status changes

Event Name Arguments Description
FirstRun the bot first starts (and not on subsequent script reloads)
Load each time the script is loaded (bot start, script enabled, scripts reloaded)
LoggedOn
  • Username: the bot's username, including D2 character name if applicable
  • Product: the bot's 4-digit product code, reversed (ex: PX2D)
The bot successfully logs in and enters chat (received SID_ENTERCHAT back from the server)
ChannelJoin the bot joins a new channel
ChannelLeave the bot leaves a channel
Close each time the script is unloaded (bot close, script disabled, scripts reloaded)
LoggedOff the bot disconnects from Battle.net
Shutdown the bot closes

Bot functions

Event Name Arguments Description
Command
  • CommandObj: an object providing details about the execution of a command
a command is issued to the bot (does not mean it was successfully executed)
MessageQueued
  • MessageID: a numeric identifier for the message
  • Message: the text of the queued message
  • Tag: a meta-tag associated with the queued message
a message was added to the bot's outgoing message queue
MessageSent
  • MessageID: a numeric identifier for the message
  • Message: the text of the sent message
  • Tag: a meta-tag associated with the sent message
a message was taken off the queue and sent to the server
Error
  • Number: a number identifying the error
  • Description: a string describing the error
  • Line: the line number in the script where the error occurred (may not always match the actual line in the script file)
  • Column: the position in the line where the error occurred
  • Text: ??
  • Source: ??
an error occurs in the execution of a script
PressedEnter
  • Text: the contents of the send box
the ENTER/RETURN key is pressed while focus is on the send box
PacketReceived
  • Protocol: a string identifying the protocol that the packet is associated with (ex: BNCS, BNLS, MCP)
  • ID: indicates the packet's format and purpose (see BNETDocs - Packet Index)
  • Length: the full length of the packet
  • Data: a string containing the raw packet data, including any headers
the bot receives a packet on one of its internal sockets
PacketSent
  • Protocol: a string identifying the protocol that the packet is associated with (ex: BNCS, BNLS, MCP)
  • ID: indicates the packet's format and purpose (see BNETDocs - Packet Index)
  • Length: the full length of the packet
  • Data: a string containing the raw packet data, including any headers
the bot sends a packet on one of its internal sockets

Chat events

Event Name Arguments Description
UserEmote
  • Username: the name of the user that sent the message
  • Flags: the flags of the user that sent the message
  • Message: the text of the message sent
a user in the channel sends an emote (/emote or /me command)
UserInChannel
  • Username: the name of the user
  • Flags: the user's chat flags
  • Message: a string describing the user's product and product-specific stats (ex: "WarCraft II: Battle.net Edition (0 wins)")
  • Ping: the user's ping
  • Product: the user's 4-digit product code, in forward order (ex: D2XP)
  • StatUpdate: TRUE if this is an update for an existing user
occurs once for each user in the channel when the bot first joins it, and again whenever a user's statstring is updated
UserJoins
UserLeaves
UserTalk
WhisperFromuser
FlagUpdate