我編寫(xiě)了一個(gè)命令,提示服務(wù)器輸入 2 個(gè)數(shù)字,然后用戶在盡可能短的時(shí)間內(nèi)添加這些數(shù)字。我正在嘗試找出一種方法來(lái) ping 得到正確答案的用戶,但我似乎無(wú)法讓它發(fā)揮作用。我嘗試應(yīng)用的一件事是添加m.author == message.author到返回行,如此處所示,但我收到一條錯(cuò)誤消息未定義。我對(duì)此還很陌生,所以很高興知道如何將其實(shí)現(xiàn)到我的代碼中,或者是否有不同的方法,因?yàn)槲蚁胍木褪悄軌蜃寵C(jī)器人 ping 發(fā)送該消息的用戶首先正確答案。@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 回答

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