Discord 音乐机器人不排队歌曲 (nextcord)
当我使用play命令时,我的机器人不会排队歌曲,它只是播放它们。我试图在使用Spotify& bot中的soundcloud。我尝试排队歌曲,我无法排队。那么,有人可以帮我吗?我已经检查了wavelink文档,但找不到任何东西。(我是这个库的初学者)
代码:
import nextcord
from nextcord.ext import commands
import wavelink
import random
import datetime
from datetime import datetime
import os
bot = commands.Bot(command_prefix=">")
@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)
emb = nextcord.Embed(description=f"Now playing {next_song.title}",color=nextcord.Color.magenta())
emb.set_image(url=next_song.thumbnail)
await ctx.send(embed=emb)
@bot.command(aliases=["p"])
async def play(ctx,*,search:wavelink.YouTubeTrack):
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):
embed=nextcord.Embed(description=f"{ctx.author.mention}: No song(s) are playing.",color=nextcord.Color.blue())
return await ctx.send(embed=embed)
else:
vc:wavelink.Player = ctx.voice_client
if vc.queue.is_empty and vc.is_playing:
await vc.play(search)
embe = nextcord.Embed(description=f"Now playing [{search.title}]({search.uri}) ",color=nextcord.Color.magenta())
embe.set_image(url=search.thumbnail)
await ctx.send(embed=embe)
else:
await vc.queue.put_wait(search)
emb = nextcord.Embed(description=f"Added [{search.title}]({search.uri}) to the queue.",color=nextcord.Color.magenta())
emb.set_image(url=search.thumbnail)
await ctx.send(embed=emb)
vc.ctx = ctx
setattr(vc,"loop",False)
@bot.command()
async def queue(ctx):
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):
embed=nextcord.Embed(description=f"{ctx.author.mention}: No song(s) are playing.",color=nextcord.Color.blue())
return await ctx.send(embed=embed)
else:
vc:wavelink.Player = ctx.voice_client
if vc.queue.is_empty:
emb = nextcord.Embed(description=f"{ctx.author.mention}: The queue is empty. Try adding songs.",color=nextcord.Color.red())
return await ctx.send(embed=emb)
lp = nextcord.Embed(title="Queue",color=nextcord.Color.blue())
queue = vc.queue.copy()
song_count = 0
for song in queue:
song_count += 1
lp.add_field(name=f"[{song_count}] Song",value=f"{song.title}")
return await ctx.send(embed=lp)
bot.run("TOKEN IS HERE JUST NOT LEAKING IT")
错误:
Traceback (most recent call last):
File "/home/runner/Solved-Music/venv/lib/python3.8/site-packages/nextcord/client.py", line 417, in _run_event
await coro(*args, **kwargs)
File "main.py", line 181, in on_wavelink_track_end
song_count += 1
File "/home/runner/Solved-Music/venv/lib/python3.8/site-packages/wavelink/queue.py", line 212, in get
raise QueueEmpty("No items in the queue.")
wavelink.errors.QueueEmpty: No items in the queue.
My bots doesn't queue the songs when i use the play command, it just plays them. Im trying to get all my commands to work before using spotify & soundcloud in the bot.So, when i use the play command & I try to queue the songs, I cannot queue them. So, can anyone help me ? I have checked the wavelink doc but I couldn't find anything.. (im a beginner with this library)
Code:
import nextcord
from nextcord.ext import commands
import wavelink
import random
import datetime
from datetime import datetime
import os
bot = commands.Bot(command_prefix=">")
@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)
emb = nextcord.Embed(description=f"Now playing {next_song.title}",color=nextcord.Color.magenta())
emb.set_image(url=next_song.thumbnail)
await ctx.send(embed=emb)
@bot.command(aliases=["p"])
async def play(ctx,*,search:wavelink.YouTubeTrack):
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):
embed=nextcord.Embed(description=f"{ctx.author.mention}: No song(s) are playing.",color=nextcord.Color.blue())
return await ctx.send(embed=embed)
else:
vc:wavelink.Player = ctx.voice_client
if vc.queue.is_empty and vc.is_playing:
await vc.play(search)
embe = nextcord.Embed(description=f"Now playing [{search.title}]({search.uri}) ",color=nextcord.Color.magenta())
embe.set_image(url=search.thumbnail)
await ctx.send(embed=embe)
else:
await vc.queue.put_wait(search)
emb = nextcord.Embed(description=f"Added [{search.title}]({search.uri}) to the queue.",color=nextcord.Color.magenta())
emb.set_image(url=search.thumbnail)
await ctx.send(embed=emb)
vc.ctx = ctx
setattr(vc,"loop",False)
@bot.command()
async def queue(ctx):
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):
embed=nextcord.Embed(description=f"{ctx.author.mention}: No song(s) are playing.",color=nextcord.Color.blue())
return await ctx.send(embed=embed)
else:
vc:wavelink.Player = ctx.voice_client
if vc.queue.is_empty:
emb = nextcord.Embed(description=f"{ctx.author.mention}: The queue is empty. Try adding songs.",color=nextcord.Color.red())
return await ctx.send(embed=emb)
lp = nextcord.Embed(title="Queue",color=nextcord.Color.blue())
queue = vc.queue.copy()
song_count = 0
for song in queue:
song_count += 1
lp.add_field(name=f"[{song_count}] Song",value=f"{song.title}")
return await ctx.send(embed=lp)
bot.run("TOKEN IS HERE JUST NOT LEAKING IT")
Error:
Traceback (most recent call last):
File "/home/runner/Solved-Music/venv/lib/python3.8/site-packages/nextcord/client.py", line 417, in _run_event
await coro(*args, **kwargs)
File "main.py", line 181, in on_wavelink_track_end
song_count += 1
File "/home/runner/Solved-Music/venv/lib/python3.8/site-packages/wavelink/queue.py", line 212, in get
raise QueueEmpty("No items in the queue.")
wavelink.errors.QueueEmpty: No items in the queue.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要将代码:
vc:wavelink.Player = ctx.voice_client if vc.queue.is_empty and vc.is_playing:
更改为代码vc:wavelink.Player = ctx.voice_client if vc.queue.is_empty 和**不是** vc.is_playing:
you need to change your code:
vc:wavelink.Player = ctx.voice_client if vc.queue.is_empty and vc.is_playing:
to the codevc:wavelink.Player = ctx.voice_client if vc.queue.is_empty and **not** vc.is_playing:
如果您遵循其他建议并将其添加到声明中。
在我的系统上,机器人会加载一首歌以添加到que并跳过
它,因为我的系统和函数的原因:is_playing不要一起播放。
行
始终返回正确,因此如果您有同样的问题,请跳过
:现在,您的机器人在使用Play命令时会播放,并且会排队未来的歌曲。
if you follow the other advice and add a not to the statement.
on my system the bot would load add a song to que and skip
it turns out forwhat ever reason my system and the function: is_playing dont play nice together.
always returned true thus skipping the line
if you are having the same issue you can try:
now your bot will play when using the play command and it will queue future songs.