为什么我的NextCord Discord Music Bot不循环或排队?
我正在制作音乐不和谐机器人,并且一直在尝试使其循环和排队歌曲。 但是,当我尝试排队一首歌时,它只是开始播放而不是排队并在控制台中显示此错误:
Ignoring exception in on_wavelink_track_end Traceback (most recent call last): File "C:\Users\Name\AppData\Local\Programs\Python\Python310\lib\site-packages\nextcord\client.py", line 415, in _run_event
await coro(*args, **kwargs) File "C:\PC Code\Python Code Files\Discord Bot\Next cord\Fish Bot Complex - NextCord.py", line 32, in on_wavelink_track_end
next_song = vc.queue.get() File "C:\Users\Name\AppData\Local\Programs\Python\Python310\lib\site-packages\wavelink\queue.py", line 212, in get
raise QueueEmpty("No items in the queue.") wavelink.errors.QueueEmpty: No items in the queue.
这是我的代码:
@bot.event
async def on_wavelink_track_end(player: wavelink.Player, track: wavelink.Track, reason):
ctx = player.ctx
vc: player = ctx.voice_client
if vc.loop:
return await vc.play(track)
next_song = vc.queue.get()
await vc.play(next_song)
await ctx.send(f"Now playing: {next_song.title}")
@bot.command(aliases=['P', 'play', 'p' ], name = 'Play', description = "Plays the music you want!")
@commands.has_role("DJ")
async def Play(ctx: commands.Context, *, search: wavelink.YouTubeTrack):
await ctx.send("Attempting to play. (Note: This is a beta bot so things may not work as intended)")
if not ctx.voice_client:
vc: wavelink.Player = await ctx.author.voice.channel.connect(cls=wavelink.Player)
elif not getattr(ctx.author.voice, "channel", None):
return await ctx.send("You need to join a VC to play music.")
else:
vc: wavelink.Player = ctx.voice_client
if vc.queue.is_empty and vc.is_playing:
await vc.play(search)
await ctx.send(f"Now Playing: {search.title}")
else:
await vc.queue.put_wait(search)
await ctx.send(f"Added `{search.title}` to the queue")
vc.ctx = ctx
setattr(vc, "loop", False)
print("Playing a song")
@bot.command(aliases=['L', 'l', 'loop' ], name = 'Loop', description = "Loops the playing music!")
@commands.has_role("DJ")
async def Loop(ctx: commands.Context):
if not ctx.voice_client:
return await ctx.send("You don't seen to be playing any music... (Note: This is a beta bot so things may not work as intended)")
elif not ctx.author.voice:
return await ctx.send("You need to join a VC to play music.")
elif not ctx.author.voice == ctx.me.voice:
return await ctx.send("You must be in the same VC as me.")
else:
vc: wavelink.Player = ctx.voice_client
try:
vc.loop ^= True
except Exception:
setattr(vc, "loop", False)
if vc.loop:
return await ctx.send("Loop has been Enabled.")
else:
return await ctx.send("Loop has been Disabled.")
@bot.command(aliases=['Q', 'q', 'queue' ], name = 'Queue', description = "Queues a song.")
@commands.has_role("DJ")
async def Queue(ctx: commands.Context):
if not ctx.voice_client:
return await ctx.send("You don't seen to be playing any music... (Note: This is a beta bot so things may not work as intended)")
elif not ctx.author.voice:
return await ctx.send("You need to join a VC to play music.")
elif not ctx.author.voice == ctx.me.voice:
return await ctx.send("You must be in the same VC as me.")
else:
vc: wavelink.Player = ctx.voice_client
if vc.queue.is_empty:
return await ctx.send("The queue is now empty.")
em = nextcord.Embed(title="Queue")
queue = vc.queue.copy()
song_count = 0
for song in queue:
song_count += 1
em.add_field(name=f"Song Number {song_count}", value=f"`{song.title}`")
return await ctx.send(embed=em)
我不确定问题所在。
I am Making a Music discord bot and I have been trying to make it loop and queue songs.
But when I try to queue a song it just starts playing it instead of queuing it and shows this error in the console:
Ignoring exception in on_wavelink_track_end Traceback (most recent call last): File "C:\Users\Name\AppData\Local\Programs\Python\Python310\lib\site-packages\nextcord\client.py", line 415, in _run_event
await coro(*args, **kwargs) File "C:\PC Code\Python Code Files\Discord Bot\Next cord\Fish Bot Complex - NextCord.py", line 32, in on_wavelink_track_end
next_song = vc.queue.get() File "C:\Users\Name\AppData\Local\Programs\Python\Python310\lib\site-packages\wavelink\queue.py", line 212, in get
raise QueueEmpty("No items in the queue.") wavelink.errors.QueueEmpty: No items in the queue.
As well as it telling me to join the VC it's in even though I already am in the same VC
Here is my code:
@bot.event
async def on_wavelink_track_end(player: wavelink.Player, track: wavelink.Track, reason):
ctx = player.ctx
vc: player = ctx.voice_client
if vc.loop:
return await vc.play(track)
next_song = vc.queue.get()
await vc.play(next_song)
await ctx.send(f"Now playing: {next_song.title}")
@bot.command(aliases=['P', 'play', 'p' ], name = 'Play', description = "Plays the music you want!")
@commands.has_role("DJ")
async def Play(ctx: commands.Context, *, search: wavelink.YouTubeTrack):
await ctx.send("Attempting to play. (Note: This is a beta bot so things may not work as intended)")
if not ctx.voice_client:
vc: wavelink.Player = await ctx.author.voice.channel.connect(cls=wavelink.Player)
elif not getattr(ctx.author.voice, "channel", None):
return await ctx.send("You need to join a VC to play music.")
else:
vc: wavelink.Player = ctx.voice_client
if vc.queue.is_empty and vc.is_playing:
await vc.play(search)
await ctx.send(f"Now Playing: {search.title}")
else:
await vc.queue.put_wait(search)
await ctx.send(f"Added `{search.title}` to the queue")
vc.ctx = ctx
setattr(vc, "loop", False)
print("Playing a song")
@bot.command(aliases=['L', 'l', 'loop' ], name = 'Loop', description = "Loops the playing music!")
@commands.has_role("DJ")
async def Loop(ctx: commands.Context):
if not ctx.voice_client:
return await ctx.send("You don't seen to be playing any music... (Note: This is a beta bot so things may not work as intended)")
elif not ctx.author.voice:
return await ctx.send("You need to join a VC to play music.")
elif not ctx.author.voice == ctx.me.voice:
return await ctx.send("You must be in the same VC as me.")
else:
vc: wavelink.Player = ctx.voice_client
try:
vc.loop ^= True
except Exception:
setattr(vc, "loop", False)
if vc.loop:
return await ctx.send("Loop has been Enabled.")
else:
return await ctx.send("Loop has been Disabled.")
@bot.command(aliases=['Q', 'q', 'queue' ], name = 'Queue', description = "Queues a song.")
@commands.has_role("DJ")
async def Queue(ctx: commands.Context):
if not ctx.voice_client:
return await ctx.send("You don't seen to be playing any music... (Note: This is a beta bot so things may not work as intended)")
elif not ctx.author.voice:
return await ctx.send("You need to join a VC to play music.")
elif not ctx.author.voice == ctx.me.voice:
return await ctx.send("You must be in the same VC as me.")
else:
vc: wavelink.Player = ctx.voice_client
if vc.queue.is_empty:
return await ctx.send("The queue is now empty.")
em = nextcord.Embed(title="Queue")
queue = vc.queue.copy()
song_count = 0
for song in queue:
song_count += 1
em.add_field(name=f"Song Number {song_count}", value=f"`{song.title}`")
return await ctx.send(embed=em)
I'm not sure on what the issue is any help is appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在您的代码上,
您需要更改
:
On your code
you need to change
to