Package dextbird
Sub-modules
dextbird.dextbird
-
Core module
dextbird.plug
dextbird.voice_client
Classes
class VoiceClient (client: discord.client.Client, channel: discord.abc.Connectable)
-
discord.py extensions voiceclient
Attributes
channel
:Union[discord.VoiceChannel, discord.StageChannel]
- Discord VoiceChannel
client
:discord.Client
- Discord.py client instance
connected
:bool
- When the client is connecting to vc, it returns
True
Expand source code
class VoiceClient(discord.VoiceProtocol): """ discord.py extensions voiceclient Attributes ---------- channel : Union[discord.VoiceChannel, discord.StageChannel] Discord VoiceChannel client : discord.Client Discord.py client instance connected : bool When the client is connecting to vc, it returns `True` """ channel: Union[discord.VoiceChannel, discord.StageChannel] def __init__(self, client: discord.Client, channel: discord.abc.Connectable): self._core: Optional[Core] = None self.client = client self.voice_server_event = asyncio.Event() self.voice_state_event = asyncio.Event() self.connected: bool = False super().__init__(client, channel) self.guild: discord.Guild = channel.guild async def connect( self, *, self_deaf: bool = False, self_mute: bool = False, **kwargs ) -> None: self._core = await Core.setup(self.client, self.guild.id, self.client.user.id) await self._core.join(self.channel.id) await self.voice_state_event.wait() await self.voice_server_event.wait() await self._core.connect() self.connected = True async def on_voice_server_update(self, data: dict) -> None: await self._core.update_server(data["endpoint"], data["token"]) self.voice_server_event.set() async def on_voice_state_update(self, data: dict) -> None: await self._core.update_state(data["session_id"], data.get("channel_id")) self.voice_state_event.set() async def ytdl(self, url: str) -> Track: """ Play music by yt-dlp Parameters ---------- url : str YouTube video url """ return await self._core.ytdl(url) def source(self, data: bytes) -> Track: """ Play music from bytes Parameters ---------- data : bytes Voice data """ return self._core.source(data) def stop(self) -> None: "Stop to play music" self._core.stop() async def disconnect(self, *args) -> None: "Disconnect from voice channel" await self._core.leave() self._core = None self.connected = False self.cleanup() async def deafen(self, deaf: bool) -> None: "Deaf connection" await self._core.deafen(deaf) async def mute(self, mute: bool) -> None: "Mute connection" await self._core.mute(mute)
Ancestors
- discord.voice_client.VoiceProtocol
Class variables
var channel : Union[discord.channel.VoiceChannel, discord.channel.StageChannel]
Methods
async def connect(self, *, self_deaf: bool = False, self_mute: bool = False, **kwargs) ‑> None
-
|coro|
An abstract method called when the client initiates the connection request.
When a connection is requested initially, the library calls the constructor under
__init__
and then calls :meth:connect
. If :meth:connect
fails at some point then :meth:disconnect
is called.Within this method, to start the voice connection flow it is recommended to use :meth:
Guild.change_voice_state
to start the flow. After which, :meth:on_voice_server_update
and :meth:on_voice_state_update
will be called. The order that these two are called is unspecified.Parameters
timeout
::class:
float``- The timeout for the connection.
reconnect
::class:
bool``- Whether reconnection is expected.
self_mute
::class:
bool``-
Indicates if the client should be self-muted.
Added in version: 2.0
self_deaf
::class:
bool``-
Indicates if the client should be self-deafened.
Added in version: 2.0
async def deafen(self, deaf: bool) ‑> None
-
Deaf connection
async def disconnect(self, *args) ‑> None
-
Disconnect from voice channel
async def mute(self, mute: bool) ‑> None
-
Mute connection
async def on_voice_server_update(self, data: dict) ‑> None
-
|coro|
An abstract method that is called when initially connecting to voice. This corresponds to
VOICE_SERVER_UPDATE
.Parameters
data
::class:
dict``- The raw :ddocs:
voice server update payload <topics/gateway-events#voice-server-update>
.
async def on_voice_state_update(self, data: dict) ‑> None
-
|coro|
An abstract method that is called when the client's voice state has changed. This corresponds to
VOICE_STATE_UPDATE
.Warning
This method is not the same as the event. See: :func:
on_voice_state_update
Parameters
data
::class:
dict``- The raw :ddocs:
voice state payload <resources/voice#voice-state-object>
.
def source(self, data: bytes) ‑> Track
-
Play music from bytes
Parameters
data
:bytes
- Voice data
def stop(self) ‑> None
-
Stop to play music
async def ytdl(self, url: str) ‑> Track
-
Play music by yt-dlp
Parameters
url
:str
- YouTube video url