'Why is my Nextcord Discord Music bot not looping or queueing?
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.
Solution 1:[1]
On your code
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")
you need to change
if vc.queue.is_empty and vc.is_playing:
to
if vc.queue.is_empty and not vc.is_playing:
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | coder |
