首页 > 解决方案 > discord.py 让机器人加入一个设置的语音频道,不一定是运行命令的人的频道

问题描述

voice_channel = bot.get_channel('channel id')
await voice_channel.connect()

我想让机器人在给出命令时加入特定的语音通道,但上面的代码给出错误“命令引发异常:AttributeError:'NoneType'对象没有属性'connect'”。

如何使机器人可以加入正确的指定语音频道?

标签: pythondiscord.py

解决方案


bot.get_channel() 接受Int,而不是String。从您的示例代码看来,您将 ID 作为字符串传递。试试这个:

# Replace the long number with your desired channel ID.
voice_channel = bot.get_channel(671603729965341934)

# Connect to the channel. Remember that non-existent
# or deleted channels also return as None.
await voice_channel.connect()

推荐阅读