audio.py 文件源码

python
阅读 28 收藏 0 点赞 0 评论 0

项目:MangoByte 作者: mdiller 项目源码 文件源码
def audioplayer(self, ctx, error_on_none=True):
        # TODO: ACCOUNT FOR WHEN THIS MESSAGE IS A PM
        if isinstance(ctx, discord.ext.commands.Context):
            if ctx.message.guild is None: # This is a private channel, so give it user
                ctx = ctx.message.author
            else:
                ctx = ctx.message.guild

        if isinstance(ctx, discord.User):
            author = ctx
            for audioplayer in self.audioplayers:
                member = audioplayer.guild.get_member(author.id)
                if member and member.voice and audioplayer.voice and audioplayer.voice.channel.id == member.voice.channel.id:
                    if botdata.guildinfo(audioplayer.guild).is_banned(member):
                        raise AudioPlayerNotFoundError("Nice try, but you're banned in the voice channel that I'm in")
                    return audioplayer
            if error_on_none:
                raise AudioPlayerNotFoundError("You're not in any voice channels that I'm in")
            else:
                return None
        elif isinstance(ctx, discord.Guild):
            guild = ctx
        elif isinstance(ctx, discord.abc.GuildChannel):
            guild = ctx.guild
        else:
            raise ValueError(f"Incorrect type '{type(ctx)}' given to audioplayer function")

        for audioplayer in self.audioplayers:
            if audioplayer.guild == guild:
                return audioplayer

        if error_on_none:
            raise AudioPlayerNotFoundError(f"I'm not in a voice channel on this server/guild. Have an admin do `{self.bot.command_prefix}summon` to put me in one.")
        else:
            return None

    # Connects an audioplayer for the correct guild to the indicated channel
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号