Liar
Liar

Reputation: 3

Discord.py ping user who inputted message

I've made a command that prompts the server with 2 numbers, and the users add the numbers in the shortest time possible. I'm trying to figure out a way to ping the user who got the correct answer, but I can't seem to get it to work. One thing I've tried applying is adding m.author == message.author to the return line, as seen here, but I get an error saying message is undefined. I'm still pretty new to this, so it'd be nice to know how to implement it into my code, or if there's a different way, as all I want is to be able to have the bot ping the user who sent the right answer first.

@client.command()
async def math(ctx):
    num_one = random.randint(1, 98)
    num_two = randint(1, 98)
    answer = num_one + num_two
    answer_string = str(answer)
    await ctx.send(f'{num_one} + {num_two}?')
    def check(m):
        return m.content == answer_string
    msg = await client.wait_for('message', check=check)
    await ctx.send(f"got the correct answer!")```

Upvotes: 0

Views: 1043

Answers (1)

Chicken Devs
Chicken Devs

Reputation: 196

You should be able to do await ctx.send(f"{msg.author.mention} got the correct answer!").

client.wait_for returns a Message object, which means it has an author attribute. You can then use the .mention attribute of a Member object(the author), which will ping them.

Upvotes: 0

Related Questions