【问题标题】:How do I create a skip command for discord music bot in discord.py?如何在 discord.py 中为不和谐音乐机器人创建跳过命令?
【发布时间】:2021-09-19 16:35:37
【问题描述】:

我尝试用discord.py 制作一个 Discord 机器人。我在跳过命令部分。 我已经完成了播放和队列命令等其他部分。

我尝试使用命令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()

【问题讨论】:

    标签: python discord.py bots


    【解决方案1】:

    我不熟悉您要做什么,但看起来 MrSpaar's answer 可能会对您有所帮助。

    根据您实现play_music() 的方式,您应该使用vc.play()after 参数。这是提供的 sn-p:

    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 的 lambda。

    【讨论】:

    • 您能否指出这是否有助于解决问题?
    • 哦,是的,忘记了。它没有为我解决问题,但事实证明我自己解决了问题。或者也许是因为我不知道如何正确地做到这一点
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-04
    • 2021-08-30
    • 2020-04-29
    • 2020-06-20
    • 2021-05-05
    • 2019-05-05
    相关资源
    最近更新 更多