【问题标题】:Discord.py disconnect from voice channelDiscord.py 断开语音通道
【发布时间】:2021-08-26 14:51:05
【问题描述】:

所以我在 discord.py 中制作了一个机器人,它加入语音通道并在延迟 3 秒后断开连接,只是为了测试如何使其断开连接。我做了很多研究,但找不到它。机器人成功连接,但无法断开连接。这是代码-

if message.content == "-p":
        channel = message.author.voice.channel
        await channel.connect()
        time.sleep(3)
        await channel.disconnect()

这是我得到的错误-

Ignoring exception in on_message
Traceback (most recent call last):
  File "C:\Users\arnha\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\client.py", line 343, in _run_event
    await coro(*args, **kwargs)
  File "c:\Users\arnha\Desktop\Music bot\bot.py", line 44, in on_message
    await channel.disconnect()
AttributeError: 'VoiceChannel' object has no attribute 'disconnect'

请帮助我。

【问题讨论】:

    标签: python discord discord.py


    【解决方案1】:

    这很不直观。您必须在voice_client 上使用disconnect(),这是guild 的一个属性。像这样:

    channel = message.author.voice.channel
    await channel.connect()
    time.sleep(3)
    guild = message.guild.voice_client
    await guild.disconnect()
    

    【讨论】:

      猜你喜欢
      • 2020-09-24
      • 2021-11-13
      • 2018-06-16
      • 1970-01-01
      • 2019-04-08
      • 1970-01-01
      • 2018-04-04
      • 2021-01-31
      • 2020-12-18
      相关资源
      最近更新 更多