Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/358.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Discord.py断开与语音频道的连接_Python_Discord_Discord.py - Fatal编程技术网

Python Discord.py断开与语音频道的连接

Python Discord.py断开与语音频道的连接,python,discord,discord.py,Python,Discord,Discord.py,因此,我在discord.py中制作了一个机器人,它加入一个语音频道,并在延迟3秒后与之断开连接,只是为了测试如何使其断开连接。我做了很多研究,但找不到。机器人已成功连接,但无法断开连接。这是密码- if message.content == "-p": channel = message.author.voice.channel await channel.connect() time.sleep(3) awa

因此,我在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'

请帮我做同样的事情。

这完全不是直觉。您必须在
voice\u客户端上使用
disconnect()
,这是
公会的属性。像这样:

channel=message.author.voice.channel
等待通道连接()
时间。睡眠(3)
guild=message.guild.voice\u客户端
等待公会。断开连接()