为什么我的NextCord Discord Music Bot不循环或排队?

发布于 2025-01-22 21:38:31 字数 4089 浏览 0 评论 0原文

我正在制作音乐不和谐机器人,并且一直在尝试使其循环和排队歌曲。 但是,当我尝试排队一首歌时,它只是开始播放而不是排队并在控制台中显示此错误:

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.

以及告诉我加入VC,即使我已经在同一VC

这是我的代码:

    @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 Discord

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

怼怹恏 2025-01-29 21:38:31

在您的代码上,

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.queue.is_empty和vc.is_playing:

如果vc.queue.is_empty而不是vc.is_playing:

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:

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文