I have a discord.py bot that I want to code to do the following things:
- When a user types the command, the bot should send the user a DM
- Then, it should add reactions to this message (A thumbs up and thumbs down)
- Finally, it should wait for the user to react with one of those reactions.
Now based on the docs and previous projects, I came up with this function for adding reactions:
async def get_reacts(user, client, message, emojis, timeout=None):
for emoji in emojis:
await message.add_reaction(emoji)
try:
def check(reaction, reactor):
return reactor.id == user.id and reaction.emoji in emojis
reaction, user = await client.wait_for("reaction_add", check=check, timeout=timeout)
return reaction.emoji
except:
pass
This code works perfectly when in a server, but when the message is in a DM, it does something peculiar. First, it doesn't detect the user reactions at all. When I put a print statement within the check function, it told me that it parsed one reaction, and that reaction was the bot itself reacting with the thumbs down. When I reacted to the message, the check function was never called.
I saw some other solutions used a Cog listener to go through all added reactions, and use a global list of messages. However, this won't work for my bot as everything it does is in one command. Additionally, it takes up a lot of memory. This is why I went with the client.wait_for
approach instead.
Is there a problem with using client.wait_for
in DMs? Should I use Cog listeners instead? Or is it a problem with my code? Any help is appreciated. Thanks in advance!
EDIT:
Intents enabled: None (Do I need an intent to check DM reactions?)
EDIT 2:
Added default intents, still the same issue
EDIT 3:
How I am using the get_reacts
function:
msg = await context.author.send("Message")
reaction = await get_reacts(context.author, self.client, msg, ["??", "??"])
See Question&Answers more detail:
os