【问题标题】:How can my Discord Bot disconnect from the Voicechannel我的 Discord Bot 如何断开与 Voicechannel 的连接
【发布时间】:2020-07-24 06:13:53
【问题描述】:

我正在尝试制作一个简单的 Discord Bot(用 Python 3 编写),它只在命令后连接和断开连接。 Connect 命令工作正常,但我的 Discconect 命令不起作用。这是包含两个命令的代码 sn-p:

async def join(message):
    channel = message.message.author.voice.channel
    await channel.connect()


@client.command(pass_context = True)
async def leave(message):
    channel = message.message.author.voice.channel
    await channel.disconnect()```

【问题讨论】:

  • 您有任何错误吗?如果是这样,您应该在问题中包含错误

标签: python python-3.x discord discord.py


【解决方案1】:

尝试将您的 leave 函数替换为:

@commands.command()
    async def leave(ctx):
        channel = ctx.message.author.voice.channel
        voice = get(self.bot.voice_clients, guild=ctx.guild)
        if voice and voice.is_connected():
            await ctx.send(f'Disconnecting from channel **{channel}**')
            await voice.disconnect()
        else:
            await ctx.send("I'm not connected in any channel")

【讨论】:

    猜你喜欢
    • 2021-07-01
    • 2021-04-10
    • 2021-10-16
    • 1970-01-01
    • 2020-08-16
    • 2017-11-20
    • 1970-01-01
    • 2022-08-15
    • 2021-08-15
    相关资源
    最近更新 更多