制作不和谐机器人时出现属性错误

问题描述 投票:0回答:1

我正在使用 Discord.py 库为我的 Discord 服务器创建一个机器人。目前,我正在尝试处理当用户从消息中删除他们的反应时会发生什么。我已将 Discord 更新到最新版本,允许使用开发者门户和通过如下代码来实现意图:

intents = discord.Intents.all()
bot = commands.Bot(command_prefix=('$', '?'), intents=intents)

这是 on_raw_reaction_remove 函数的代码:

    channel = 867854256647176252
    message = 867855236861132860
    if payload.channel_id == channel and payload.message_id == message:
        guild = bot.get_guild(payload.guild_id)
        member = guild.get_member(payload.user_id)
        emoji = payload.emoji
        global channels
        channels = str(channels)
        channels = channels.split()
        if str(emoji.name) == '🙂' :
            role = discord.utils.get(guild.roles, name='Offtopic')
            for index in range(len(channels) - 1, -1, -1):
                if channels[index] == 'Offtopic':
                    channels.pop(index)  
            await payload.member.remove_roles(role)

反应消除后产生的错误:

Ignoring exception in on_raw_reaction_remove
Traceback (most recent call last):
  File "/home/meri/lib/python3.8/site-packages/discord/client.py", line 343, in _run_event
    await coro(*args, **kwargs)
  File "bot.py", line 420, in on_raw_reaction_remove
    await payload.member.remove_roles(role)
AttributeError: 'NoneType' object has no attribute 'remove_roles'

类似问题的答案都无法帮助解决这种情况,我们将不胜感激。

python discord discord.py
1个回答
1
投票

NoneType 表示您正在访问的值 (

payload.member
) 设置为 None。

© www.soinside.com 2019 - 2024. All rights reserved.