本文介紹了如何提及命令的發送者?不和諧.py的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我創建了一個超級簡單的 .report <person>
命令.我有它,所以當有人鍵入它時它將被發送到某個頻道.我想做的是讓它顯示報告其他用戶的用戶的名稱.我不知道該怎么做.有誰知道最好的方法嗎?
I created a super simple .report <person>
command. I have it so it will be sent to a certain channel when someone types it. What I wanted to do is have it display the name of the user who reported the other user. I don't know how to go about doing that. Does anyone know the best way?
@bot.command()
async def report(*, message):
await bot.delete(message)
await bot.send_message(bot.get_channel("479177111030988810"), message)
推薦答案
你可以這樣做,獲取上下文 (ctx) 并從中獲取消息的內容及其作者
You could do something like this, where you take the context (ctx) and from it get the contents of the message and its author
@bot.command(pass_context=True)
async def report(ctx):
await bot.delete_message(ctx.message)
report = f""{ctx.message.content[8:]}" sent by {ctx.message.author}"
await bot.send_message(bot.get_channel("479177111030988810"), report)
這篇關于如何提及命令的發送者?不和諧.py的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!