Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
555 views
in Technique[技术] by (71.8m points)

python - AttributeError: 'NoneType' object has no attribute 'count' discord.py

The code:

@bot.event
async def on_raw_reaction_add(payload):
    channel = bot.get_channel(payload.channel_id)
    msg = await channel.fetch_message(payload.message_id)
    emoji = payload.emoji
    author = payload.member
    emoji_count = discord.utils.get(msg.reactions, emoji=emoji).count
    if payload.channel_id == channel_play:
        # THE LINE 1
        buffer = bot.get_channel(772553683145457694)
        if author in buffer.members:
            if int(emoji_count) > 1:
                ...

The error:

Ignoring exception in on_raw_reaction_add
Traceback (most recent call last):
File "C:UsersplaysAppDataLocalProgramsPythonPython38-32libsite-packagesdiscordclient.py", 
line 312, in _run_event
await coro(*args, **kwargs)
File "C:UsersplaysOneDriveРабочий столPythonot2.py", line 124, in on_raw_reaction_add
emoji_count = discord.utils.get(msg.reactions, emoji=emoji).count
AttributeError: 'NoneType' object has no attribute 'count'

If the line of code that creates the error will be replaced to THE LINE 1, the error will not occure. Also, the same error happens if I write the emoji_count line in any other place of code except THE LINE 1. But the problem is that the emoji_count is used in many places of the on_raw_reaction_add function, and I can't use it only in one piece of code, which is the case when payload.channel_id is the same as channel_play_id. So, why does this error happen, and how to fix it?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...