用于Red Discordbot的Lavalink客户端库
Red-Lavalink的Python项目详细描述
使用Asyncio框架为Python3.5编写的Lavalink客户端库。 此库可能用于其他项目,因为它不包含特定于红色的代码或逻辑。
但是,需要注意的是,此库仅支持使用discord.py的项目。
要安装:
pip install red-lavalink
用法
importlavalinkfromdiscord.ext.commandsimportBotbot=Bot()@bot.eventasyncdefon_ready():lavalink.initialize(bot,host='localhost',password='password',rest_port=2332,ws_port=2333)asyncdefsearch_and_play(voice_channel,search_terms):player=awaitlavalink.connect(voice_channel)tracks=awaitplayer.search_yt(search_terms)player.add(tracks[0])awaitplayer.play()
洗牌
defshuffle_queue(player_id,forced=True):player=lavalink.get_player(player_id)ifnotforced:player.maybe_shuffle(sticky_songs=0)""" `player.maybe_shuffle` respects `player.shuffle` And will only shuffle if `player.shuffle` is True. `player.maybe_shuffle` should be called every time you would expect the queue to be shuffled. `sticky_songs=0` will shuffle every song in the queue. """else:player.force_shuffle(sticky_songs=3)""" `player.force_shuffle` does not respect `player.shuffle` And will always shuffle the queue. `sticky_songs=3` will shuffle every song after the first 3 songs in the queue. """
关机时,请确保执行以下操作:
await lavalink.close()