我正在尝试为响应角色构建一个不和谐的机器人。为此,我尝试将on_reaction_add与fetch_message结合使用,以检查添加的响应是否与机器人发送的消息有关,但fetch_message不断出现各种错误。这是代码:
@bot.command()
async def createteams(ctx):
msg = await ctx.send("React to get into your teams")
await msg.add_reaction("1️⃣")
await msg.add_reaction("2️⃣")
await msg.add_reaction("3️⃣")
await msg.add_reaction("4️⃣")
await msg.add_reaction("5️⃣")
await msg.add_reaction("6️⃣")
await msg.add_reaction("7️⃣")
await msg.add_reaction("8️⃣")
@bot.event
async def on_reaction_add(reaction, user):
id = reaction.message.id
if await reaction.message.author.fetch_message(reaction.message.id) == "React to get into your teams":
print("Success")
这给了我错误
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/discord/client.py", line 312, in _run_event
await coro(*args, **kwargs)
File "hypixel.py", line 60, in on_reaction_add
fetch = await reaction.message.author.fetch_message(id)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/discord/abc.py", line 955, in fetch_message
channel = await self._get_channel()
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/discord/member.py", line 243, in _get_channel
ch = await self.create_dm()
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/discord/member.py", line 109, in general
return getattr(self._user, x)(*args, **kwargs)
AttributeError: 'ClientUser' object has no attribute 'create_dm'
但是当我去复制我反应的消息的ID时,它与打印变量id
相同,但是它仍然显示Message Not Found
谢谢
答案 0 :(得分:0)
我发现了问题,您不能将fetch_message与需要使用频道的用户一起使用,因此我将代码更改为
await reaction.message.channel.fetch_message(id)
它起作用了:)