feat: validate bot voice channel permissions

This commit is contained in:
mmacierzanka committed 2026-09-13 16:14:38 +02:00
1 parent 76f63057bc
commit 210f03b0d3
6 files changed
+60 -2

No files matched your search

+6
View File
@@ -63,6 +63,12 @@ async def connect(
if not isinstance(channel, discord.VoiceChannel):
raise HTTPException(status_code=404, detail="Voice channel not found")
if channel.guild.me and not channel.permissions_for(channel.guild.me).connect:
raise HTTPException(
status_code=403,
detail=f"Bot nie ma uprawnień do połączenia z kanałem {channel.name}",
)
guild_id = channel.guild.id
# Rozłączamy wyłącznie na tym samym serwerze - inne serwery grają dalej.
existing = guilds.voice_client(guild_id)
+1
View File
@@ -138,6 +138,7 @@ class StatusService:
for guild in self._guilds.guilds()
if selected_guild is None or guild.id == selected_guild.id
for channel in guild.voice_channels
if guild.me and channel.permissions_for(guild.me).connect
]
def _guilds_payload(self) -> list[dict[str, Any]]:
+11 -1
View File
@@ -24,7 +24,17 @@ class MusicCogBase(commands.Cog):
voice_client = interaction.guild.voice_client
if voice_client is None:
await interaction.user.voice.channel.connect()
user_channel = interaction.user.voice.channel
if interaction.guild.me and not user_channel.permissions_for(interaction.guild.me).connect:
await interaction.response.send_message(
embed=message_embed(
"Brak uprawnień",
f"Bot nie ma uprawnień do połączenia z kanałem **{user_channel.name}**.",
),
ephemeral=True,
)
return False
await user_channel.connect()
elif voice_client.channel != interaction.user.voice.channel:
await interaction.response.send_message(
embed=message_embed(
+10
View File
@@ -34,6 +34,16 @@ class VoiceCog(MusicCogBase, name="Voice"):
async def connect(
self, interaction: discord.Interaction, channel: discord.VoiceChannel
) -> None:
if interaction.guild.me and not channel.permissions_for(interaction.guild.me).connect:
await interaction.response.send_message(
embed=message_embed(
"Brak uprawnień",
f"Bot nie ma uprawnień do połączenia z kanałem **{channel.name}**.",
),
ephemeral=True,
)
return
existing = self.player.voice_client(interaction.guild.id)
if existing:
await existing.disconnect()