如何在discord.py中为discord音乐机器人创建跳过命令?

62lalag4  于 2021-09-08  发布在  Java
关注(0)|答案(1)|浏览(412)

我试着和机器人吵架 discord.py . 我在跳过命令区。我已经完成了其他部分,比如play和queue命令。
我试着使用这个命令 self.vc.stop() 停止这首歌,跳到下一首歌,但它不起作用,有人能帮我吗?下面是我执行的详细跳过命令:

class music_cog(commands.Cog):
   # all the stuff over here
   @commands.command(aliases=["continue"])
   async def skip(self, ctx):
       if self.vc != "":
           self.vc.stop()
           # plays the next song
           await self.play_music()
sxissh06

sxissh061#

我不知道你想做什么,但看来斯帕尔先生的回答可能会对你有所帮助。
取决于您的实现方式 play_music() ,你应该使用 after 论据 vc.play() . 以下是提供的代码段:

import asyncio

def play_next(ctx, source):
    if len(self.song_queue) >= 1:
        del self.song_queue[0]
        vc = get(self.bot.voice_clients, guild=ctx.guild)
        vc.play(discord.FFmpegPCMAudio(source=source, after=lambda e: play_next(ctx))
        asyncio.run_coroutine_threadsafe(ctx.send("No more songs in queue."))

这里的关键是使用 skip() 作为一个羔羊 after 据我所知。

相关问题