cog.py 文件源码

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

项目:dogbot 作者: slice 项目源码 文件源码
def join(self, ctx):
        """Summons the bot to your voice channel."""
        msg = await ctx.send('\N{RUNNER} Connecting to voice...')

        state = self.state_for(ctx.guild)

        # already connected?
        if state.connected:
            return await msg.edit(content='I\'m already playing music in `{}`.'.format(state.channel))

        # can't join if we aren't in a voice channel.
        if ctx.author.voice is None:
            return await msg.edit(content='I can\'t join you if you aren\'t in a voice channel.')

        # the channel that the command invoker is in
        ch = ctx.author.voice.channel

        # check if we can join that channel.
        if not ctx.guild.me.permissions_in(ch).connect:
            return await msg.edit(content='\N{LOCK} I can\'t connect to that channel.')

        try:
            log.debug('Connecting to %s.', ch)
            await ch.connect()
        except TimeoutError:
            await msg.edit(content='\N{ALARM CLOCK} Couldn\'t connect, I took too long to reach Discord\'s servers.')
            log.warning('Timed out while connecting to Discord\'s voice servers.')
        except ClientException:
            await msg.edit(content='\N{CONFUSED FACE} I\'m already connected.')
            log.warning('I couldn\'t detect being connected.')
        else:
            await msg.edit(content='\N{OK HAND SIGN} Connected!')
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号