cog.py 文件源码

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

项目:dogbot 作者: slice 项目源码 文件源码
def _play(self, ctx: DogbotContext, url, *, search=False):
        msg = await ctx.send(f'\N{INBOX TRAY} {random.choice(SEARCHING_TEXT)}')

        # grab the source
        url = 'ytsearch:' + url if search else url
        try:
            source = await YouTubeDLSource.create(url, ctx.bot)
        except youtube_dl.DownloadError:
            return await msg.edit(content='\U0001f4ed YouTube gave me nothing.')
        except YouTubeError as yterr:
            return await msg.edit(content='\N{CROSS MARK} ' + str(yterr))

        disp = '**{}**'.format(source.title)

        state = self.state_for(ctx.guild)

        if state.is_playing():
            # add it to the queue
            log.debug('Adding to queue.')
            state.queue.append(source)
            await msg.edit(content=f'\N{LINKED PAPERCLIPS} Added {disp} to queue.')
        else:
            # play immediately since we're not playing anything
            log.debug('Playing immediately.')
            state.play(source)
            await msg.edit(content=f'\N{MULTIPLE MUSICAL NOTES} Playing {disp}.')
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号