Reputation: 1
I'm having an odd issue when trying to detect a reaction on a sent DM.
First, I'm checking if the !hello
command is being run, then sending the author of that message a DM asking if they like the bot. The user is to input their opinion using the Reactions and get a response in the original channel of the !hello
command. What I have found is that the message it is wait_for
is not the sent DM, but the previously sent !hello
command. Perhaps I have overlooked something in documentation, but how do I change what message the Bot should be listening for? Any help or pointers in the right direction are greatly appreciated.
import discord
import asyncio
# Set up the bot
token = "TOKEN"
intents = discord.Intents(messages=True, message_content=True, guilds=True, reactions=True)
client = discord.Client(intents=intents)
@client.event
async def on_message(message):
if message.content.startswith("!hello"):
try:
# Send the DM
dm = await message.author.send("Hello! Do you like this bot? React with 🇾 or 🇳")
# React to the message with the options
await dm.add_reaction('🇾')
await dm.add_reaction('🇳')
# Wait for the user's reaction
def check(reaction, user):
return user != client.user and str(reaction.emoji) in ['🇾', '🇳']
reaction, user = await client.wait_for('reaction_add', timeout=15.0, check=check)
# Do something with the reaction
if str(reaction.emoji) == '🇾':
await message.channel.send(f'{user.name} liked the bot')
elif str(reaction.emoji) == '🇳':
await message.channel.send(f'{user.name} did not like the bot')
except discord.Forbidden:
await message.channel.send("I'm sorry, I am unable to send you a DM.")
except asyncio.TimeoutError:
await message.channel.send("You did not react in time.")
client.run(token)
I have gone through several Stack Overflow posts describing similar issues, but none have explicitly solved my problem. The biggest thing I suspect could be intents, but I cannot pinpoint which intents nor Discord Developer Portal Permissions that have to be enabled. And I would prefer to keep my bot not fully capable of destroying a server with Admin Permissions.
Upvotes: 0
Views: 83
Reputation: 1
The solution to the problem I was having lies in Intents. The necessary Intent required for a Bot to read reactions using wait_for('reaction_add')
within a DM are the GUILD_MEMBER
Privileged Intents. (Not realising they are separate from Bot Permissions)
All that had to be done was include members=True
within my set of subscribed Intents.
Example from code above: intents = discord.Intents(messages=True, message_content=True, guilds=True, reactions=True, members=True)
Here is where the required Privileged Intent can be found within the Developer Portal
Hope this helps someone with the same issue I had.
Upvotes: 0