python - discord.py 让机器人加入一个设置的语音频道,不一定是运行命令的人的频道
问题描述
voice_channel = bot.get_channel('channel id')
await voice_channel.connect()
我想让机器人在给出命令时加入特定的语音通道,但上面的代码给出错误“命令引发异常:AttributeError:'NoneType'对象没有属性'connect'”。
如何使机器人可以加入正确的指定语音频道?
解决方案
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()
推荐阅读
- android - 在android studio中的textview中移动实际文本
- javascript - 上传图片后,Vue Firebase 无法获取图片 url
- arduino - 如何在arduino中按WINDOWS + R?
- r - 无法将 O'Reilly 的书“R in a Nutshell”中的包“nutshell”安装到 Mac 上
- python - Peewee 在使用 IntegerField() 时使用 0 表示无效整数,但我希望将其设置为 NULL
- flutter - 如何将简单的条形图添加到底部导航栏
- javascript - WebdriverIO 中是否有 ScenarioContext - 我们如何为键设置值,然后跨测试场景使用此数据?
- java - java方法覆盖中的奇怪无限循环
- java - 原因:无法确定合适的驱动程序类:spring boot using eclipse
- c# - System.RAP 报告 azure service fabric 项目的属性 IStatelessServiceInstance.OpenDuration 错误警告