Python discord 模块,PCMVolumeTransformer() 实例源码

我们从Python开源项目中,提取了以下6个代码示例,用于说明如何使用discord.PCMVolumeTransformer()

项目:nyx    作者:Cappycot    | 项目源码 | 文件源码
def play_file(self, ctx, sound, volume=1):
        """Plays a file from the local filesystem"""

        if ctx.voice_client is None:
            if ctx.author.voice.channel:
                await ctx.author.voice.channel.connect()
            else:
                return await ctx.send("Not connected to a voice channel.")

        if ctx.voice_client.is_playing():
            ctx.voice_client.stop()

        def done(e):
            if e:
                print("Player error: %s" % e)
            if not ctx.voice_client.is_playing():
                ctx.bot.loop.create_task(ctx.voice_client.disconnect())

        source = discord.PCMVolumeTransformer(
            discord.FFmpegPCMAudio(join(folder, sound)))
        source.volume = volume
        ctx.voice_client.play(source, after=done)

        # await ctx.send('Now playing: {}'.format(query))
项目:Red_Star    作者:medeor413    | 项目源码 | 文件源码
def create_source(entry):
        source = PCMVolumeTransformer(FFmpegPCMAudio(entry["download_url"], **entry["kwargs"]))
        source.download_url = entry["download_url"]
        source.url = entry["url"]
        source.yt = entry["yt"]
        source.is_live = entry["is_live"]
        source.title = entry["title"]
        source.duration = entry["duration"]
        source.description = entry["description"]
        source.upload_date = entry["upload_date"]
        source.kwargs = entry["kwargs"]
        return source
项目:dogbot    作者:slice    | 项目源码 | 文件源码
def now_playing(self, ctx):
        """Shows what's playing."""
        if not ctx.guild.voice_client.is_playing():
            return await ctx.send('Nothing\'s playing at the moment.')

        state = self.state_for(ctx.guild)
        src = state.to_loop if isinstance(state.vc.source, PCMVolumeTransformer) else state.vc.source.info

        minutes, seconds = divmod(src['duration'], 60)
        await ctx.send('**Now playing:** {0[title]} {0[webpage_url]} ({1:02d}:{2:02d})'.format(src, minutes, seconds))
项目:nyx    作者:Cappycot    | 项目源码 | 文件源码
def play_file(self, ctx, *, query):
        """Plays a file from the local filesystem"""

        if ctx.voice_client is None:
            if ctx.author.voice.channel:
                await ctx.author.voice.channel.connect()
            else:
                return await ctx.send("Not connected to a voice channel.")

        if ctx.voice_client.is_playing():
            ctx.voice_client.stop()

        source = discord.PCMVolumeTransformer(discord.FFmpegPCMAudio(query))
        ctx.voice_client.play(source, after=lambda e: print(
            'Player error: %s' % e) if e else None)

        await ctx.send('Now playing: {}'.format(query))
项目:MangoByte    作者:mdiller    | 项目源码 | 文件源码
def play_next_clip(self):
        clip = self.next_clip()

        self.voice.play(discord.FFmpegPCMAudio(clip.audiopath), after=self.done_talking)
        self.voice.source = discord.PCMVolumeTransformer(self.voice.source)
        self.voice.source.volume = clip.volume
        print("playing: " + clip.audiopath)
        if self.last_clip != None and clip.audiopath != self.last_clip.audiopath:
            remove_if_temp(self.last_clip.audiopath)
        self.last_clip = clip

    # try queueing an mp3 to play
项目:Red_Star    作者:medeor413    | 项目源码 | 文件源码
def process_song_data(self, ydl, url, entry):
        """
        Just packing some code into a function to make fetch_song_data more readable
        :param ydl: youtube_dl object
        :param url: original url of the request
        :param entry: request data
        :return: dictionary of parameters
        """
        t_dict = DotDict({})
        self.logger.info(f'processing URL {entry["title"]}')
        if self.plugin_config["download_songs"]:
            filename = ydl.prepare_filename(entry)
            self.storage["stored_songs"][filename] = time.time()
        else:
            filename = entry['url']
        # t_source = PCMVolumeTransformer(FFmpegPCMAudio(filename, **kwargs))  # out, out, damn spot!
        t_dict['download_url'] = filename
        t_dict['url'] = entry.get('webpage_url')
        t_dict['yt'] = ydl
        t_dict['is_live'] = bool(entry.get('is_live'))
        t_dict['duration'] = ceil(entry.get('duration', 0))

        is_twitch = 'twitch' in url

        if is_twitch:
            # twitch has 'title' and 'description' sort of mixed up.
            t_dict['title'] = entry.get('description')
            t_dict['description'] = None
        else:
            t_dict['title'] = entry.get('title')
            t_dict['description'] = entry.get('description')

        # upload date handling
        date = entry.get('upload_date')
        if date:
            try:
                date = datetime.datetime.strptime(date, '%Y%M%d').date()
            except ValueError:
                date = None

        t_dict['upload_date'] = date
        return t_dict