我編寫了一個命令,提示服務器輸入 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!")```
1 回答

莫回無
TA貢獻1865條經驗 獲得超7個贊
你應該能夠做到await ctx.send(f"{msg.author.mention} got the correct answer!")
。
client.wait_for返回一個Message對象,這意味著它有一個author屬性。然后,您可以使用成員對象(作者)的 .mention 屬性,這將 ping 他們。
添加回答
舉報
0/150
提交
取消