【问题标题】:helpme command, cannot find author's voice channel discord.pyhelpme 命令,找不到作者的语音频道 discord.py
【发布时间】:2021-03-13 04:03:45
【问题描述】:

您可以使用 !h 和聊天机器人类型(作者姓名、需要帮助、@staff 以及需要帮助的人在哪个语音频道中) 如何找到命令作者的语音通道? 这就是我尝试过的: (我现在正在on_message 活动中尝试)

@client.event
async def on_message(message):
    print(f'member is in {message.author.voice_channel}')

但是当我运行它并在聊天中输入一些内容时,我收到了这个错误:

Ignoring exception in on_message
Traceback (most recent call last):
  File "C:\Users\Ido Shaked\Desktop\citybot\venv\lib\site-packages\discord\client.py", line 333, in _run_event
    await coro(*args, **kwargs)
  File "C:/Users/Ido Shaked/Desktop/citybot/citycode.py", line 18, in on_message
    print(f'member is in {message.author.voice_channel}')
AttributeError: 'Member' object has no attribute 'voice_channel'

【问题讨论】:

    标签: python discord discord.py


    【解决方案1】:

    错误告诉你到底出了什么问题 - Member 没有 voice_channel 属性。你必须通过message.author.voice.channel获得它

    【讨论】:

    • 我替换了这个,现在它给我输入了这个错误:`忽略 on_message Traceback 中的异常(最后一次调用):文件“C:\Users\Ido Shaked\Desktop\citybot\venv\lib\ site-packages\discord\client.py”,第 333 行,在 _run_event await coro(*args, **kwargs) 文件“C:/Users/Ido Shaked/Desktop/citybot/citycode.py”,第 18 行,on_message print(f'member is in {message.author.voice.channel}') AttributeError: 'NoneType' object has no attribute 'channel `
    • 如果用户不在语音频道中,member.voice 将返回None。您可以使用if member.voice: 来检查成员当前是否连接到语音频道。
    猜你喜欢
    • 2019-11-17
    • 2021-11-06
    • 2018-04-04
    • 2020-12-21
    • 2019-04-08
    • 2021-11-11
    • 2021-11-14
    • 2021-06-06
    • 2022-01-23
    相关资源
    最近更新 更多