本文介紹了從 discord.py rewrite 發送一個 pm的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我試圖弄清楚如何從 discord.py 重寫機器人發送 pm.我不能做 ctx.author.send("context") 因為它向消息作者以外的人發送消息.這是我到目前為止在搜索用戶時所擁有的代碼,它總是帶有 NONE 的值
I'm trying to figure out how to send a pm from a discord.py rewrite bot. I can't do ctx.author.send("context") because it messaging someone other than the author of the message. here's the code that I have so far when I'm searching for a user it always comes with the value of NONE
@bot.command()
async def spam(ctx, author, message, amount):
print(author)
print(ctx.author)
victim = bot.get_user(author)
print(victim)
if not (victim == None):
for i in range(int(amount)):
await victim.send(message)
else:
print("NOPE")
它有輸出
GIMMY READY......
Denard#0759
Denard#0759
None
NOPE
推薦答案
您可以使用 converter 自動解析 victim
的 User
對象.
You can use a converter to resolve the User
object of your victim
automatically.
@bot.command()
async def spam(ctx, victim: discord.User, amount, *, message):
for _ in range(amount):
await victim.send(message)
然后您可以使用他們的姓名、ID 或提及來指定他們:
You can then use their name, id, or a mention to specify them:
!spam Denard 1 spam spam spam
!spam @Denard 1 spam spam spam
!spam 1234 1 spam spam spam
這篇關于從 discord.py rewrite 發送一個 pm的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!