Add unjoin_voice command to allow users to disconnect from voice channels
This commit is contained in:
parent
b1bcb44dac
commit
5e75dd73a8
1 changed files with 29 additions and 1 deletions
|
@ -42,6 +42,14 @@ class VoiceBot:
|
||||||
guild_ids=self.guild_ids,
|
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:
|
async def random_connect(self) -> None:
|
||||||
while True:
|
while True:
|
||||||
|
@ -136,6 +144,11 @@ class VoiceBot:
|
||||||
|
|
||||||
async def disconnect_voice(self, guild: discord.Guild) -> None:
|
async def disconnect_voice(self, guild: discord.Guild) -> None:
|
||||||
if vo := self.vo.pop(guild.id, 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()
|
await vo.disconnect()
|
||||||
|
|
||||||
async def join_voice(self, ctx: discord.ApplicationContext) -> None:
|
async def join_voice(self, ctx: discord.ApplicationContext) -> None:
|
||||||
|
@ -153,6 +166,21 @@ class VoiceBot:
|
||||||
delete_after=30,
|
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(
|
async def on_voice_state_update(
|
||||||
self,
|
self,
|
||||||
member: discord.Member,
|
member: discord.Member,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue