输入消息的ping用户Discord.py



我制作了一个命令,用2个数字提示服务器,用户在尽可能短的时间内添加数字。我正试图找到一种方法来ping得到正确答案的用户,但我似乎无法让它发挥作用。我尝试应用的一件事是将m.author == message.author添加到返回行,如图所示,但我收到一个错误,说消息未定义。我对此还很陌生,所以很高兴知道如何将其实现到我的代码中,或者如果有不同的方法,因为我只想让机器人ping首先发送正确答案的用户。

@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!")```

您应该能够执行await ctx.send(f"{msg.author.mention} got the correct answer!")

client.wait_fo返回一个Message对象,这意味着它具有author属性。然后,您可以使用Member对象(作者(的.acture属性,该属性将ping它们。

最新更新