tether developers
Contents

Docs

Voice

A bot joins a voice channel with gateway opcode 4 and gets a LiveKit address and token, not Discord's voice protocol.

A bot joins voice channels the way a person does, with gateway opcode 4, and tether answers with a LiveKit address and token. Discord's own voice protocol (UDP, xsalsa) is not offered, so @discordjs/voice and discord.py's voice code have to be swapped for a LiveKit SDK (Python livekit, Node @livekit/rtc-node). A server with no LiveKit has voice switched off: voice_enabled is false in Get Instance, and a join is refused with 90030.

Joining

  1. Send opcode 4: {guild_id, channel_id, self_mute, self_deaf}.
  2. Wait for VOICE_SERVER_UPDATE (to the asking session only): {guild_id, channel_id, endpoint, token}. endpoint is a LiveKit URL and token a LiveKit access token for that one room, valid for about 10 minutes.
  3. Connect to endpoint with token using a LiveKit SDK and publish one microphone track.

Leave with opcode 4 and channel_id: null. Muting or deafening yourself is opcode 4 with the same channel: the state is re-dispatched and you get no new token. To get a fresh token, leave and join again.

When a join is refused

A refused opcode 4 gets VOICE_STATE_ERROR {guild_id, channel_id, code, message, retry_after?} (Discord silently ignores a refused join). The previous voice state stands. Read it, so a refused join fails at once instead of timing out:

Code Why
10004 The bot is not a member of guild_id.
10003 No such channel in that server.
50024 Not a voice channel.
50001 No View Channel.
50013 No Connect.
90031 The channel is full (user_limit); Move Members skips.
90030 The server has no LiveKit.
90034 The channel is end-to-end encrypted: no bots (below).
90003 Too many opcode 4 requests (20 per 10 seconds).

A malformed opcode 4 closes the socket with 4002. A bot cannot join a call in a direct message (20001).

Encrypted voice channels: no bots

A server can turn on end-to-end encryption for a voice channel (the field voice_e2ee on the channel). Sound and video there are encrypted on people's devices with keys they give each other, so a bot, which would have to hold those keys, cannot join: opcode 4 for that channel is refused with 90034 (VOICE_E2EE_BOTS). The same goes for music bots and the player: they work in the server's other voice channels. The mode of a room is fixed while anyone is in it, so a server owner turning the switch on takes effect when the channel is next empty; a bot already in the channel stays until the room empties. Direct message calls are never open to bots.

What a bot may do in the room

What the bot may do in LiveKit follows from its permissions in that channel, exactly as for a person: Connect to join (and to receive everyone's audio and video, unless it is server-deafened), Speak to publish audio, Stream to publish a camera or a screen share. A moderator can mute, deafen, move or disconnect it (Modify Guild Member) and LiveKit enforces it.

The bot has an ordinary voice state: it counts towards user_limit, shows in the channel list, and appears in GUILD_CREATE.voice_states and VOICE_STATE_UPDATE. A music bot is hidden only while a song plays in the player, and only if the server asked for it (The music player).

Resuming

A gateway socket that resumes keeps the voice state. A session that ends for good (a clean close with 1000 or 1001, the resume window over, INVALID_SESSION) ends its voice connection; after a new IDENTIFY send opcode 4 again.

Any bot in voice can hear the call

A bot in a voice channel can receive everyone's audio and video, like a person, whether it is visible or hidden. That is how voice works here, and it is why servers only add bots they trust, and why adding a bot needs Manage Server. Hiding a bot hides who is in the call; it does not stop the bot listening. More in Privacy for bots.