wait_for() from discord.py don't work in dm

Viewed 239

This code works in server channels, but does not work in private messages of users. Is there an alternative feature for private messages?

@client.event
async def on_message(message):
    if message.author == client.user:
        return

    if message.content.startswith('$thumb'):
        channel = message.channel
        await channel.send('Send me that  reaction, mate')

        def check(reaction, user):
            return user == message.author and str(reaction.emoji) == ''

        try:
            reaction, user = await client.wait_for('reaction_add', timeout=10.0, check=check)
        except asyncio.TimeoutError:
            await channel.send('')
        else:
            await channel.send('')

I found some problems similar to mine and rewrote the code, but it didn't help:

discord.py wait_for('reaction_add') functioning differently with direct messages

Discord.py Bot Reactions in DMs

import discord

intents = discord.Intents.default()
intents.members = True

client = discord.Client()

@client.event
async def on_message(message):
    if message.author == client.user:
        return

    if message.content.startswith('$thumb'):
        
        msg = await message.channel.send(f'Hi {message.author.mention}')
        await msg.add_reaction('✅')

        def check(reaction, user):
            print(user.id, message.author.id)
            return reaction.message.id == msg.id and user.id == message.author.id and str(reaction.emoji) == '✅'

        try:
            reaction, user = await client.wait_for('reaction_add', timeout=30.0, check=check)
        except asyncio.TimeoutError:
            pass
        else:
            await message.channel.send('success')

client.run(token)
1 Answers

Just making an intents variable doesn't make your bot use it.

client = discord.Client(intents=intents)
Related