Add unjoin_voice command to allow users to disconnect from voice channels

This commit is contained in:
Edgar P. Burkhart 2025-05-04 20:58:42 +02:00
parent b1bcb44dac
commit 5e75dd73a8
Signed by: edpibu
GPG key ID: 9833D3C5A25BD227

View file

@ -42,6 +42,14 @@ class VoiceBot:
guild_ids=self.guild_ids,
)
)
self.bot.add_application_command(
discord.SlashCommand(
self.unjoin_voice,
name="unjoin",
description="Déconnecter du channel vocal",
guild_ids=self.guild_ids,
)
)
async def random_connect(self) -> None:
while True:
@ -131,11 +139,16 @@ class VoiceBot:
await self.disconnect_voice(channel.guild)
if vo is None or vo.channel != channel:
vo = await channel.connect()
self.vo[channel.guild.id] = vo
self.vo[channel.guild.id] = vo
return vo
async def disconnect_voice(self, guild: discord.Guild) -> None:
if vo := self.vo.pop(guild.id, None):
if self.cambai is not None:
source = await discord.FFmpegOpusAudio.from_probe(
self.cambai.tts("À plus les jeunes !")
)
await vo.play(source, wait_finish=True)
await vo.disconnect()
async def join_voice(self, ctx: discord.ApplicationContext) -> None:
@ -153,6 +166,21 @@ class VoiceBot:
delete_after=30,
)
async def unjoin_voice(self, ctx: discord.ApplicationContext) -> None:
if ctx.user.voice:
await ctx.respond(
f"Disconnecting from voice channel {ctx.user.voice.channel}.",
ephemeral=True,
delete_after=30,
)
await self.disconnect_voice(ctx.user.voice.channel.guild)
else:
await ctx.respond(
"You are not connected to a voice channel.",
ephemeral=True,
delete_after=30,
)
async def on_voice_state_update(
self,
member: discord.Member,