Skip to content

5. Websocket

rainy w/rain edited this page May 14, 2024 · 2 revisions

Introduction

ByteBlaze provide an event system that track player activity of the bot through websocket. This is for developing dashboard with an easy way for middle developer.

This doc will explain, providing example clearly for each event

Note: If the field title have ?, that means data can nullable

Connect

You can establish a WebSocket connection against the path /v1/websocket

When opening a websocket connection, you must supply 2 required headers:

Header Name Description
authorization The password you set in your ByteBlaze config
guild-id The guild id which you want bot to open websocket

Note: If you use the guild id that not exist on byteblaze to connect websocket, it won't send any events

Op (event)

playerCreate

Dispatched when a player is created.

Field Type Description
op string The event name
guild string The guild that have this event
Example Payload
{
  "op": "playerCreate",
  "guild": "1084918771967344662",
}

playerDestroy

Dispatched when a player is destroyed.

Field Type Description
op string The event name
guild string The guild that have this event
Example Payload
{
  "op": "playerDestroy",
  "guild": "1084918771967344662",
}

playerPause

Dispatched when a player is paused.

Field Type Description
op string The event name
guild string The guild that have this event
Example Payload
{
  "op": "playerPause",
  "guild": "1084918771967344662",
}

playerResume

Dispatched when a player is resume.

Field Type Description
op string The event name
guild string The guild that have this event
Example Payload
{
  "op": "playerResume",
  "guild": "1084918771967344662",
}

playerUpdate

Dispatched when a player is update.

Field Type Description
op string The event name
guild string The guild that have this event
position number The current position of this track
Example Payload
{
  "op": "playerUpdate",
  "guild": "1084918771967344662",
  "position": 5880,
}

trackStart

Dispatched when a track in player is started.

Field Type Description
op string The event name
guild string The guild that have this event
data? Track object The track info of now playing track
Example Payload
{
  "op": "trackStart",
  "guild": "1084918771967344662",
  "data": {
    "title": "2Pac - Dear Mama",
    "uri": "https://www.youtube.com/watch?v=Mb1ZvUDvLDY",
    "length": 276000,
    "thumbnail": "https://i.ytimg.com/vi/Mb1ZvUDvLDY/maxresdefault.jpg",
    "author": "2PacVEVO",
    "requester": {
      "id": "898728768791789628",
      "username": "rainyxeon",
      "globalName": "rainy w/🌧",
      "defaultAvatarURL": "https://cdn.discordapp.com/avatars/898728768791789628/734d8a64053d0e4d4c7d32bfd4c2079e.webp?size=128",
    }
  }
}

trackEnd

Dispatched when a track in player is ended.

Field Type Description
op string The event name
guild string The guild that have this event
data? Track object The track info of previous track
mode Mode string The end mode of this event
Example Payload
{
  "op": "trackEnd",
  "guild": "1084918771967344662",
  "data": {
    "title": "2Pac - Dear Mama",
    "uri": "https://www.youtube.com/watch?v=Mb1ZvUDvLDY",
    "length": 276000,
    "thumbnail": "https://i.ytimg.com/vi/Mb1ZvUDvLDY/maxresdefault.jpg",
    "author": "2PacVEVO",
    "requester": {
      "id": "898728768791789628",
      "username": "rainyxeon",
      "globalName": "rainy w/🌧",
      "defaultAvatarURL": "https://cdn.discordapp.com/avatars/898728768791789628/734d8a64053d0e4d4c7d32bfd4c2079e.webp?size=128",
    }
  }
}

memberJoin

Dispatched when a memeber is joined.

Field Type Description
op string The event name
guild string The guild that have this event
userId string The discord id of memeber that join the voice
Example Payload
{
  "op": "memberJoin",
  "guild": "1084918771967344662",
  "userId": "898728768791789628",
}

memberLeave

Dispatched when a memeber is leaved.

Field Type Description
op string The event name
guild string The guild that have this event
userId string The discord id of memeber that leave the voice
Example Payload
{
  "op": "memberLeave",
  "guild": "1084918771967344662",
  "userId": "898728768791789628",
}

playerVolume

Dispatched when a player volume is changed.

Field Type Description
op string The event name
guild string The guild that have this event
volume number The changed player volume
Example Payload
{
  "op": "playerVolume",
  "guild": "1084918771967344662",
  "volume": 90,
}

playerLoop

Dispatched when a player volume is changed.

Field Type Description
op string The event name
guild string The guild that have this event
mode Mode string The changed player loop mode
Example Payload
{
  "op": "playerLoop",
  "guild": "1084918771967344662",
  "mode": "queue",
}

playerClearQueue

Dispatched when a player queue is cleared.

Field Type Description
op string The event name
guild string The guild that have this event
Example Payload
{
  "op": "playerClearQueue",
  "guild": "1084918771967344662",
}

playerQueueRemove

Dispatched when a player track from queue is removed.

Field Type Description
op string The event name
guild string The guild that have this event
data Track object The track info
index number The index for removed track in array
Example Payload
{
  "op": "playerQueueRemove",
  "guild": "1084918771967344662",
  "data": {
    "title": "2Pac - Dear Mama",
    "uri": "https://www.youtube.com/watch?v=Mb1ZvUDvLDY",
    "length": 276000,
    "thumbnail": "https://i.ytimg.com/vi/Mb1ZvUDvLDY/maxresdefault.jpg",
    "author": "2PacVEVO",
    "requester": {
      "id": "898728768791789628",
      "username": "rainyxeon",
      "globalName": "rainy w/🌧",
      "defaultAvatarURL": "https://cdn.discordapp.com/avatars/898728768791789628/734d8a64053d0e4d4c7d32bfd4c2079e.webp?size=128",
    }
  },
  "index": 4
}

playerQueueInsert

Dispatched when a player track from queue is inserted.

Field Type Description
op string The event name
guild string The guild that have this event
data Track object The track info
index number The index for inserted track in array
Example Payload
{
  "op": "playerQueueInsert",
  "guild": "1084918771967344662",
  "data": {
    "title": "2Pac - Dear Mama",
    "uri": "https://www.youtube.com/watch?v=Mb1ZvUDvLDY",
    "length": 276000,
    "thumbnail": "https://i.ytimg.com/vi/Mb1ZvUDvLDY/maxresdefault.jpg",
    "author": "2PacVEVO",
    "requester": {
      "id": "898728768791789628",
      "username": "rainyxeon",
      "globalName": "rainy w/🌧",
      "defaultAvatarURL": "https://cdn.discordapp.com/avatars/898728768791789628/734d8a64053d0e4d4c7d32bfd4c2079e.webp?size=128",
    }
  },
  "index": 4
}

playerQueueShuffle

Dispatched when a player track from queue is inserted.

Field Type Description
op string The event name
guild string The guild that have this event
queue Track array The track queue info that shuffered
Example Payload
{
  "op": "playerQueueShuffle",
  "guild": "1084918771967344662",
  "queue": [
    {
      "title": "2Pac - Dear Mama",
      "uri": "https://www.youtube.com/watch?v=Mb1ZvUDvLDY",
      "length": 276000,
      "thumbnail": "https://i.ytimg.com/vi/Mb1ZvUDvLDY/maxresdefault.jpg",
      "author": "2PacVEVO",
      "requester": {
        "id": "898728768791789628",
        "username": "rainyxeon",
        "globalName": "rainy w/🌧",
        "defaultAvatarURL": "https://cdn.discordapp.com/avatars/898728768791789628/734d8a64053d0e4d4c7d32bfd4c2079e.webp?size=128",
      }
    }
  ],
}

playerQueueSkip

Dispatched when a player skip to another index of queue.

Field Type Description
op string The event name
guild string The guild that have this event
queue Track array The track queue info that shuffered
Example Payload
{
  "op": "playerQueueSkip",
  "guild": "1084918771967344662",
  "queue": [
    {
      "title": "2Pac - Dear Mama",
      "uri": "https://www.youtube.com/watch?v=Mb1ZvUDvLDY",
      "length": 276000,
      "thumbnail": "https://i.ytimg.com/vi/Mb1ZvUDvLDY/maxresdefault.jpg",
      "author": "2PacVEVO",
      "requester": {
        "id": "898728768791789628",
        "username": "rainyxeon",
        "globalName": "rainy w/🌧",
        "defaultAvatarURL": "https://cdn.discordapp.com/avatars/898728768791789628/734d8a64053d0e4d4c7d32bfd4c2079e.webp?size=128",
      }
    }
  ],
}