这是我上一个问题的更新(AttributeError:';NoneType';对象没有属性';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:UsersplaysAppDataLocalProgramsPythonPython38-32libsite-packagesdiscordclient.py",
line 312, in _run_event
await coro(*args, **kwargs)
File "C:UsersplaysOneDriveРабочий столPythonbot2.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表情符号都能正常工作?代码中应该写些什么?
if emoji.is_custom_emoji():
emoji_count = discord.utils.get(msg.reactions, emoji=emoji).count
else:
emoji_count = discord.utils.get(msg.reactions, emoji = emoji.name).count