【发布时间】:2021-03-28 02:11:26
【问题描述】:
我希望机器人检查带有新表情符号的频道,然后根据新表情符号做不同的事情。它可以正常工作,直到表情符号在私人频道上,这使得 bot.get_channel(payload.channel_id) 返回无。
我在用户或会员 ID 上遇到了同样的问题。 payload.member 返回 None,但 bot.get_user(payload.user_id) 返回成员对象。那么,有没有这样的东西,但有渠道?用什么来获取 DMChannel 对象?
@bot.event
async def on_raw_reaction_add(payload):
print(bot.get_channel(payload.channel_id), payload.channel_id) # This line will be deleted, it is used for showing the problem.
if payload.user_id != None:
channel = bot.get_channel(payload.channel_id)
msg = await channel.fetch_message(payload.message_id)
emoji = payload.emoji
author = payload.member
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
if payload.channel_id == channel_i:
if emoji_count > 1:
...
反应在DM通道的输出,错误是因为通道是NoneType,是上一行造成的。
None 782664385889959976
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 122, in on_raw_reaction_add
msg = await channel.fetch_message(payload.message_id)
AttributeError: 'NoneType' object has no attribute 'fetch_message'
【问题讨论】:
标签: python discord.py