【问题标题】:discord py stop playing (voice)discord py 停止播放(语音)
【发布时间】:2022-12-17 23:27:20
【问题描述】:

我正在用 discord py 制作一个 discord bot 但我有一个问题: 我的问题是,当我们亲爱的会员点击 $stop 命令时,声音不应该继续 * 机器人不应该死,只有声音应该停止 我的代码:

@app.command()
async def stop(ctx):
    voice = discord.utils.get(app.voice_clients, guild=ctx.guild)
    if voice == None:
        await ctx.send(f"hey {ctx.author.mention} first bot need to join a voice channel!")
    elif (ctx.author.voice) == None:
        await ctx.send(f"hey {ctx.author.mention} first you need join to a voice channel!")
    else:
        # voice_1 = ctx.message.author.voice.channel
        await voice.stop()

【问题讨论】:

    标签: python discord.py


    【解决方案1】:

    您可以使用 disconnect() 函数:

    async def stop(ctx):
        # ...
        else:
            # ...
            await voice.disconnect()
    

    这将断开机器人与语音通道的连接。

    【讨论】:

    • *机器人不应该死,只有声音应该停止
    【解决方案2】:

    出于某种原因,您需要检查机器人是否在语音通道中,或者,然后您可以断开它

        async def _leave(self, ctx:commands.Context):
            voiceChannel = ctx.voice_client
            if not voiceChannel:
                await ctx.send("Bot not in any voice channel")
            
            await voiceChannel.disconnect()
            await ctx.send(f"Disconnected from {voiceChannel.channel}")```
    

    【讨论】:

      猜你喜欢
      • 2022-01-21
      • 1970-01-01
      • 1970-01-01
      • 2022-07-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多