voice.py 文件源码

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

项目:BuffBot 作者: Cmoen11 项目源码 文件源码
def play_music(self, link):
        # Get the voice channel the commanding user is in
        trigger_channel = self.music_server
        # Return with a message if the user is not in a voice channel
        if trigger_channel is None:
            await self.bot.say("You're not in a voice channel right now")
            return
        if self.voice:
            if self.voice.channel.id != trigger_channel.id:
                # If the bot is in voice, but not in the same channel, move to the commanding user
                await self.voice.move_to(trigger_channel)
        else:
            # If the bot is not in a voice channel, join the commanding user
            self.voice = await self.bot.join_voice_channel(trigger_channel)
        # Stop the player if it is running, to make room for the next one
        if self.player:
            self.player.stop()
        # Create a StreamPlayer with the requested link
        self.player = await self.voice.create_ytdl_player(link)

        await global_methods.music_playing(self.player, self.bot, self.music_server.server)   # print out music information

        self.player.volume = self.volume                                                # set the volume
        self.player.start()                                                             # starts the song
        await self.bot.change_presence(game=discord.Game(name=self.player.title))       # change bot presence

        self.seconds_to_next = self.player.duration
        await self.queue_is_alive()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号