mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-07 03:38:53 -05:00
Properly handle connect and speak permissions
This commit is contained in:
parent
e8d0c25eee
commit
371f8d0f61
@ -70,6 +70,12 @@ class AuthorNotConnected(NotConnected):
|
|||||||
class VoiceNotConnected(NotConnected):
|
class VoiceNotConnected(NotConnected):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
class UnauthorizedConnect(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
|
class UnauthorizedSpeak(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class ConnectTimeout(NotConnected):
|
class ConnectTimeout(NotConnected):
|
||||||
pass
|
pass
|
||||||
@ -976,9 +982,12 @@ class Audio:
|
|||||||
await self.bot.say("You must join a voice channel before I can"
|
await self.bot.say("You must join a voice channel before I can"
|
||||||
" play anything.")
|
" play anything.")
|
||||||
return
|
return
|
||||||
if not can_connect:
|
except UnauthorizedConnect:
|
||||||
await self.bot.say("I don't have permissions to join your"
|
await self.bot.say("I don't have permissions to join your"
|
||||||
" voice channel.")
|
" voice channel.")
|
||||||
|
except UnauthorizedSpeak:
|
||||||
|
await self.bot.say("I don't have permissions to speak in your"
|
||||||
|
" voice channel.")
|
||||||
else:
|
else:
|
||||||
await self._join_voice_channel(voice_channel)
|
await self._join_voice_channel(voice_channel)
|
||||||
else: # We are connected but not to the right channel
|
else: # We are connected but not to the right channel
|
||||||
@ -1049,9 +1058,12 @@ class Audio:
|
|||||||
await self.bot.say("You must join a voice channel before I can"
|
await self.bot.say("You must join a voice channel before I can"
|
||||||
" play anything.")
|
" play anything.")
|
||||||
return
|
return
|
||||||
if not can_connect:
|
except UnauthorizedConnect:
|
||||||
await self.bot.say("I don't have permissions to join your"
|
await self.bot.say("I don't have permissions to join your"
|
||||||
" voice channel.")
|
" voice channel.")
|
||||||
|
except UnauthorizedSpeak:
|
||||||
|
await self.bot.say("I don't have permissions to speak in your"
|
||||||
|
" voice channel.")
|
||||||
else:
|
else:
|
||||||
await self._join_voice_channel(voice_channel)
|
await self._join_voice_channel(voice_channel)
|
||||||
else: # We are connected but not to the right channel
|
else: # We are connected but not to the right channel
|
||||||
@ -1472,7 +1484,11 @@ class Audio:
|
|||||||
channel = author.voice_channel
|
channel = author.voice_channel
|
||||||
if channel is None:
|
if channel is None:
|
||||||
raise AuthorNotConnected
|
raise AuthorNotConnected
|
||||||
if channel.permissions_for(server.me):
|
elif channel.permissions_for(server.me).connect is False:
|
||||||
|
raise UnauthorizedConnect
|
||||||
|
elif channel.permissions_for(server.me).speak is False:
|
||||||
|
raise UnauthorizedSpeak
|
||||||
|
else:
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user