【问题标题】:discord.py make a bot join a set voice channel, not necessarily the channel of the person running the commanddiscord.py 让机器人加入一个设置的语音频道,不一定是运行命令的人的频道
【发布时间】:2021-09-19 11:54:27
【问题描述】:
voice_channel = bot.get_channel('channel id')
await voice_channel.connect()

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

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

【问题讨论】:

  • get_channel 的参数应该是一个 int。你用的是字符串吗?

标签: python discord.py


【解决方案1】:

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()

【讨论】:

  • 很高兴听到这个消息!如果现在一切正常,记得将其标记为答案。
猜你喜欢
  • 2020-08-30
  • 2020-10-04
  • 1970-01-01
  • 1970-01-01
  • 2023-02-25
  • 2019-04-08
  • 2018-06-16
  • 1970-01-01
  • 2021-07-13
相关资源
最近更新 更多