【问题标题】:How to make a bot join voice channels discord.py如何让机器人加入语音频道 discord.py
【发布时间】:2020-08-30 05:55:24
【问题描述】:

我正在使用 discord.py 创建音乐机器人,但在将机器人连接到语音频道时遇到问题。我使用 Cog 将音乐功能与其他功能区分开来。

@commands.command()
async def join_voice(self, ctx):
    channel = ctx.author.voice.channel
    print(channel.id)
    await self.client.VoiceChannel.connect()

但我得到了错误: AttributeError: 'NoneType' object has no attribute 'channel'

我已经查看了此处的所有文档和所有类似问题,但仍然没有解决方案!

有人可以帮忙吗?

【问题讨论】:

    标签: python python-3.x discord.py discord.py-rewrite


    【解决方案1】:

    你真的很亲密!你唯一需要改变的是:

    @commands.command()
    async def join_voice(self, ctx):
        connected = ctx.author.voice
        if connected:
            await connected.channel.connect() #  Use the channel instance you put into a variable
    

    您所做的是抓取 VoiceChannel 类对象,而不是用户连接到的实际 VoiceChannel 实例。这就是你的错误出现的地方,因为它试图找到一个不存在的语音通道。

    很高兴看到进展,继续努力!

    【讨论】:

    • 我不敢相信又是你!对我来说,你真的是编码世界中最好的人!非常感谢!
    • 哈哈,我们生活的小世界:)不用担心!
    • 最后一件事!它现在说我需要 PyNaCl 库,所以我使用了pip install PyNaCl,但它不会导入到项目中
    • 您收到 ImportError 了吗?
    • 错误提示 discord.ext.commands.errors.ExtentionFailed: Extension 'cogs.Music' raised an error: ModuleNotFoundError: No module named 'PyNaCl'
    【解决方案2】:

    【讨论】:

      猜你喜欢
      • 2020-10-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-16
      • 2020-10-15
      • 2019-04-08
      • 2022-01-04
      • 2019-05-05
      相关资源
      最近更新 更多