Hello! If you came across this library, you probably tried to implement voice functions with interactions.py, but that was not possible, since it natively does not support voice.
But don't worry! With voice
you can do exactly that! We not only add the VOICE_STATE_UPDATE
event but also the ability to connect to voice channels and transmit audio.
This will be a basic guide on how to install and use this library.
pip install -U interactions-voice
This library is an extension for interactions.py
, what gives it the ability to connect to voice and send data and to
listen to the voice_state_update
event.
from interactions import CommandContext, Channel
from interactions.ext.voice import VoiceState, VoiceClient
bot: VoiceClient = VoiceClient(token="...")
@bot.event
async def on_voice_state_update(vs: VoiceState):
print(vs.self_mute)
...
@bot.command(name="connect", description="...", options=[...])
async def connect(ctx: CommandContext, channel: Channel):
await bot.connect_vc(channel_id=int(channel.id), guild_id=int(ctx.guild_id), self_deaf=True, self_mute=False)
await bot.play(file="C:/...")
If you do not want to use the VoiceClient
object, you can also use the library this way:
from interactions import Client, CommandContext, Channel
from interactions.ext.voice import setup, VoiceState
bot: Client = Client(token="...")
setup(bot)
@bot.event
async def on_voice_state_update(vs: VoiceState):
print(vs.self_mute)
...
@bot.command(name="connect", description="...", options=[...])
async def connect(ctx: CommandContext, channel: Channel):
await bot.connect_vc(channel_id=int(channel.id), guild_id=int(ctx.guild_id), self_deaf=True, self_mute=False)
await bot.play(file="C:/...")