【发布时间】:2021-04-13 03:20:12
【问题描述】:
这是我上一个问题的更新 (AttributeError: 'NoneType' object has no attribute 'count' discord.py)
问题在于 Unicode 表情符号使 emoji_count = ... 行产生错误。那是因为 Unicode 表情符号返回None 或NoneType,所以emoji = emoji 也返回None,所以整个函数都会产生错误。
代码:
@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:
if author in buffer.members:
if int(emoji_count) > 1:
...
...
await msg.remove_reaction(emoji, author)
错误:
Ignoring exception in on_raw_reaction_add
Traceback (most recent call last):
File "C:\Users\plays\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\client.py",
line 312, in _run_event
await coro(*args, **kwargs)
File "C:\Users\plays\OneDrive\Рабочий стол\Python\bot2.py", line 125, in on_raw_reaction_add
emoji_count = discord.utils.get(msg.reactions, emoji = emoji).count
AttributeError: 'NoneType' object has no attribute 'count'
我该如何解决这个问题,以便自定义和 Unicode 表情符号都能正常工作?代码应该写什么?
【问题讨论】: