[英]Discord.py private messages
我正在嘗試制作一個 discord 機器人,它使用以下命令向某人發送 DM:
!messagesteve hello world
它會直接向我想要的人發送消息。
我嘗試了以下方法,但無濟於事:
@client.command(pass_context=True)
async def dm(ctx):
user=await client.get_user_info("381870129706958")
await client.send_message(user, "test")
任何幫助表示贊賞。
好像您正在使用 d.py (v0.16.x) 的舊文檔。 最新版本正在重寫 (v1.x)。
其中一項更改是自動隱含上下文(您不需要pass_context=True
)並且發送消息的語法已更改,您將在示例中看到:
@client.command()
async def dm(ctx, member: discord.Member, *, message):
try:
await member.send(message)
except: # this will error if the user has blocked the bot or has server dms disabled
await ctx.send("Sorry, that user had DMs disabled!")
else:
await ctx.send(f"Successfully sent {member} a DM!")
用法,假設前綴為!
,該命令的用法將是:
,dm @Skyonimous Hey there, I'm DMing you from a bot!
*
在 arguments “consumes rest”中,這意味着它后面的參數( message
)將作為一個完整的參數,不管空格的數量,所以如果你願意,你可以將整個段落發送給用戶!
如果您有什么需要我澄清的,我將非常樂意!
參考:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.