async def connect(self, channel): """ Connect to a voice channel :param channel: The voice channel to connect to :return: """ # We're using discord's websocket, not lavalink if not channel.guild == self.guild: raise InvalidArgument("The guild of the channel isn't the the same as the link's!") if channel.guild.unavailable: raise IllegalAction("Cannot connect to guild that is unavailable!") me = channel.guild.me permissions = me.permissions_in(channel) if not permissions.connect and not permissions.move_members: raise BotMissingPermissions(["connect"]) self.set_state(State.CONNECTING) payload = { "op": 4, "d": { "guild_id": channel.guild.id, "channel_id": str(channel.id), "self_mute": False, "self_deaf": False } } await self.bot._connection._get_websocket(channel.guild.id).send_as_json(payload)
def predicate(ctx): guild = ctx.guild me = guild.me if guild is not None else ctx.bot.user permissions = ctx.author.voice.channel.permissions_for(me) missing = [ perm for perm, value in perms.items() if getattr(permissions, perm) != value ] if not missing: return True raise BotMissingPermissions(missing)
async def predicate(ctx): if ctx.guild is None: raise NoPrivateMessage() permissions = ctx.guild.me.guild_permissions missing = [perm for perm, value in kwargs.items() if getattr(permissions, perm, None) != value] if not missing: return True raise BotMissingPermissions(missing)
async def predicate(ctx): if not isinstance(ctx.channel, TextChannel): return True permissions = await ctx.channel.permissions_for(await ctx.guild.me()) missing = [ perm for perm, value in perms.items() if getattr(permissions, perm) != value ] if not missing: return True raise BotMissingPermissions(missing)
def on_message_bot_has_permissions( guild: Guild, channel: TextChannel, bot_user: ClientUser, **perms: Any ) -> Optional[NoReturn]: user = guild.me if guild is not None else bot_user permissions = channel.permissions_for(user) missing = [ perm for perm, value in perms.items() if getattr(permissions, perm) != value ] if not missing: return None raise BotMissingPermissions(missing)
async def connect(self, channel): """ Connect to a voice channel :param channel: The voice channel to connect to :return: """ # We're using discord's websocket, not lavalink if channel.guild.id != self.guild_id: raise InvalidArgument( "The guild of the channel isn't the the same as the link's!") if channel.guild.unavailable: raise IllegalAction("Cannot connect to guild that is unavailable!") me = channel.guild.me permissions = me.permissions_in(channel) if (not permissions.connect or len(channel.members) >= channel.user_limit >= 1) and not permissions.move_members: raise BotMissingPermissions(["connect"]) self.set_state(State.CONNECTING) # payload = { # "op": 4, # "d": { # "guild_id": self.guild_id, # "channel_id": str(channel.id), # "self_mute": False, # "self_deaf": False # } # } # await self.bot._connection._get_websocket(self.guild_id).send_as_json(payload) await self._get_shard_socket(self.bot.shard_id ).voice_state(self.guild_id, str(channel.id)) start = time.monotonic() while not (me.voice and me.voice.channel): await asyncio.sleep(0.1) if start - time.monotonic() >= 10: raise IllegalAction( "Couldn't connect to the channel within a reasonable timeframe!" )
async def _play_music(self, ctx: SlashContext, query: Union[str, List[str]], is_playlist: bool = False): await ctx.defer() if not ctx.author.voice: raise NotConnectedToVoice if not self.__can_connect(ctx): raise BotMissingPermissions(["Connect"]) lang = await self.bot.get_guild_bot_lang(ctx.guild_id) content = get_content("MUSIC_COMMANDS", lang) player: lavalink.DefaultPlayer = self.bot.lavalink.player_manager.get( ctx.guild_id) if player is None: player = self.bot.lavalink.player_manager.create( ctx.guild_id, endpoint=str(ctx.guild.region)) if not ctx.voice_client: player.store("channel", ctx.channel.id) await ctx.author.voice.channel.connect(cls=LavalinkVoiceClient) await ctx.guild.change_voice_state( channel=ctx.author.voice.channel, self_deaf=True) tracks = None if isinstance(query, List) and is_playlist: tracks = [ await self.__get_tracks(ctx, player, _query) for _query in query ] else: tracks = [await self.__get_tracks(ctx, player, query)] await self._added_to_queue(ctx, tracks, content) if not player.is_playing: await self._send_message(ctx, tracks[0], content) await player.play()
def __local_check(ctx): if not check_botperm('attach_files', ctx=ctx): raise BotMissingPermissions(('attach_files', )) return True