Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

So basically i was making a modmail system and the problem was we wanted the person who dmed the bot has to react to ? if he reacts then the bot has to reply him "OK" but the code was not working so what is the problem how to fix it?

import discord
import asyncio

client = discord.Client()

@client.event
async def on_message(message):
  # empty_array = []
  # modmail_channel = discord.utils.get(client.get_all_channels(), name="mod-mail")

  if message.author == client.user:
      return

  if str(message.channel.type) == "private":
    embed = discord.Embed(title='Confirmation',
    color=0x03d692)
    embed.add_field(name="You're sending this message to **The Dynamic Legends**", value="React with :white_check_mark: to confirm." + "
To cancel this request, react with :x:.", inline=False)

    confirmation_msg = await message.author.send(embed=embed)

    await confirmation_msg.add_reaction('?')
    await confirmation_msg.add_reaction('?')

    sent_users = []
    sent_users.append(message.author.name)
    
    try:
      print('Working')
      
      def check1(reaction, user):
        return user == client.user and user!='Mod Mail Humara#5439' and str(reaction.emoji) == '?'

      reaction, user = await client.wait_for("reaction_add", timeout=30.0, check=check1)

      # print(reaction, user)
      if str(reaction.emoji) == '?':
        message.author.send('yes)      

client.run('TOKEN')


question from:https://stackoverflow.com/questions/65643996/cannot-check-reaction-in-discord-py

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
272 views
Welcome To Ask or Share your Answers For Others

1 Answer

There's a logic problem in the check func

return user == client.user

It simply doesn't make sense, instead of == use != and don't put the user!='Mod Mail Humara#5439' part

Your check func fixed:

def check1(reaction, user):
    return user != client.user and str(reaction.emoji) == '?'

Also message.author.send is a coroutine, so you need to await it

await message.author.send("whatever")

Your code:

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

    if isinstance(message.channel, discord.DMChannel):
        embed = discord.Embed(title='Confirmation', color=0x03d692)
        embed.add_field(name="You're sending this message to **The Dynamic Legends**", value="React with :white_check_mark: to confirm." + "
To cancel this request, react with :x:.", inline=False)

        confirmation_msg = await message.author.send(embed=embed)

        await confirmation_msg.add_reaction('?')
        await confirmation_msg.add_reaction('?')

        sent_users = []
        sent_users.append(message.author.name)

        try:
            def check1(reaction, user):
                return user != client.user and str(reaction.emoji) == '?'

            reaction, user = await client.wait_for("reaction_add", timeout=30.0, check=check1)

            if str(reaction.emoji) == '?':
                await message.author.send('yes')
            

        except Exception as e:
            pass

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...