Files
zyrarbot/zyrarbot/ui/bot/cogs/voice_cog.py
T
mmacierzanka d6bd302165
Backend / Lint i formatowanie (pull_request) Successful in 3s
Backend / Testy i kontrakt API (pull_request) Successful in 10s
Panel / Lint, typy i build (pull_request) Successful in 18s
Backend / Testowy build obrazu (pull_request) Successful in 15s
feat: restore the last queue per server
2026-08-21 17:10:40 +02:00

41 lines
1.4 KiB
Python

from __future__ import annotations
import discord
from discord.ext import commands
from zyrarbot.ui.bot.cogs.common import MusicCogBase
class VoiceCog(MusicCogBase, name="Voice"):
"""Obsługa zdarzeń i rozłączania z kanałów głosowych."""
@commands.Cog.listener()
async def on_voice_state_update(
self,
member: discord.Member,
before: discord.VoiceState,
after: discord.VoiceState,
) -> None:
is_bot_leaving = (
self.bot.user
and member.id == self.bot.user.id
and before.channel is not None
and after.channel is None
)
if is_bot_leaving:
self.player.save_queue(before.channel.guild.id)
self.player.clear(before.channel.guild.id)
await self.player.trigger_state_change()
@discord.app_commands.command(name="leave", description="Odłącz bota od kanału głosowego")
async def leave(self, interaction: discord.Interaction) -> None:
if interaction.guild.voice_client is None:
await interaction.response.send_message(
"Nie jestem na kanale głosowym.", ephemeral=True
)
return
self.player.save_queue(interaction.guild.id)
await interaction.guild.voice_client.disconnect()
self.player.clear(interaction.guild.id)
await interaction.response.send_message("Rozłączono z kanału głosowego.")