我想让我的机器人与语音频道断开,当没有剩下的发挥。所有的命令都是用齿轮写成的。
我试着使用vc.queue.is_empty(),但是它会跳过下面的一首歌
唱完一首歌
B歌-不演奏
系统:跳过B歌曲并断开连接
我希望如下所示:
唱完一首歌
B歌-不演奏
系统:播放B歌。B曲完成后,与语音频道断开连接。
async def on_wavelink_track_end(self, player: wavelink.Player, track: wavelink.Track, reason):
with open('Music.json', 'r', encoding='utf8') as jfile:
jdata = json.load(jfile)
guild = player.guild
vc: player = guild.voice_client
channel = self.bot.get_channel(int(jdata[str(guild.id)]['Older_Channel']))```
if self.is_looped == True: #it work
await vc.play(track)
else:
if have_next_song: #here, i do not know what should put in there
await vc.play(next_song)
embed=discord.Embed(title=f"Now Playing", color=0xf1c40f)
embed.add_field(name="Title", value=f"**[{next_song.title}]({next_song.uri})**", inline=False)
embed.add_field(name="Author", value=next_song.author, inline=False)
embed.add_field(name="Duration | Seconds", value=next_song.length, inline=False)
await channel.send(embed=embed)
elif do_not_have_next_song: #here also I do not know what should put in there
await vc.disconnect()
embed=discord.Embed(title=f"Nothing Left to Play", description=f"There is nothing left to play, left voice channel.", color=0xf1c40f)
await channel.send(embed=embed)发布于 2022-07-06 18:42:29
(此源代码将检查队列是否为空,如果是,并且没有更多的歌曲可播放,它将断开连接)尝试如下:
import wavelink, discord
from discord.ext import commands
from discord import Embed, Colour
from datetime import datetime
@bot.event
async def on_wavelink_track_end(player: wavelink.Player, track, reason):
if not player.queue.is_empty:
next_song = await player.queue.get_wait()
await player.play(next_song)
else:
await player.disconnect()
@bot.command()
async def skip(ctx: commands.Context):
try:
vc: wavelink.Player = ctx.voice_client
if not vc.queue.is_empty:
await vc.stop()
else:
return await ctx.send("Queue Is Empty, What Now ¯\_(ツ)_/¯")
except:
embed = Embed(
description='**Join A VC First!**',
color=Colour.random(),
timestamp=datetime.now()
)
await ctx.reply(embed=embed)https://stackoverflow.com/questions/71660413
复制相似问题