0
votes

I'm trying to build a discord bot for reaction roles. To do this, I'm trying to use the on_reaction_add combined with fetch_message to check if the reaction added was to the message that the bot sent but I keep getting various error with fetch_message. Here is the code:

@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")

This gives me the error

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'

But when I go and copy the ID of the message I reacted to, its the same as the printed variable id but it still says Message Not Found

Thanks

1
Are you sure you've pasted all your code? It looks like you're trying to call to an unexisting create_dm function somewhere in your code. - Marc Sances
This is all the code that relevant but ill put the whole thing if it helps - Tanuj KS
its calling the create_dm from the on_Reaction_add according to the error message - Tanuj KS
can you paste the full stack trace? - Marc Sances
I pasted all the code - Tanuj KS

1 Answers

1
votes

I figured out the issue, you can't use fetch_message with user it needs to be channel so I changed my code to

await reaction.message.channel.fetch_message(id) and it worked :)