我的 Discord 机器人在 Wavelink 上的播放命令不起作用,如何解决?



这是我的bot的播放命令:

@client.tree.command(name="play", description="Play some music")
@app_commands.describe(musicname="The name of the music you want to play")
async def play(interaction:Interaction, musicname:str):
'''Play music'''
search = await wavelink.YouTubeTrack.search(query=musicname, return_first=True)
if not getattr(interaction.user.voice, "channel", None):
return await interaction.response.send_message("You are not in a voice channel", ephemeral=True)
elif not interaction.guild.voice_client:
voiceclient: wavelink.Player = await interaction.user.voice.channel.connect(cls=wavelink.Player, self_deaf=True)
else:
voiceclient: wavelink.Player = interaction.guild.voice_client
if not voiceclient.is_playing():
await voiceclient.play(search)
await interaction.response.send_message(f"Now playing `{search.title}`")
else:
await voiceclient.queue.put_wait(search)
await interaction.response.send_message(f"Added `{search.title}` to the queue")

同样适用于on_wavink_track_end:

@client.event
async def on_wavelink_track_end(player:Player, track:YouTubeTrack, reason:str):
'''When track ends'''
voiceclient: Player = player.guild.voice_client
if voiceclient.loop:
return await voiceclient.play(track)
elif not voiceclient.queue.is_empty:
next_song = voiceclient.queue.get()
await voiceclient.play(next_song)
await player.interaction.response.send_message(f"Now playing `{next_song.title}`")
else:
print("finished playing")

只要我输入Discord/play something, bot就会在控制台写入"finished playing",这意味着bot甚至不会播放歌曲,而是在执行命令时完成播放。请帮帮我吧!

期望:播放音乐现实:写进聊天"玩东西";并进入控制台"玩完">

我很容易地修复了它:
我只是替换了节点lavallinking。到lavalink.botsuniversity.ml,它开始工作了。

最新更新