在 discord.py 中发送 dm

问题描述

我试图让它使用 on_message 事件向指定用户发送 dm。 到目前为止,我已经从提到的用户那里获取雪花 ID,但找不到向该用户发送 dm 的方法。 我已经找了好几个小时了,但没有找到答案,请帮忙。

解决方法

这取决于您使用的 discord.py 版本,但假设您使用的版本高于 1.0:

使用user.send(message)

更具体地说,我需要一个代码片段或更深入地描述您正在尝试做什么

要从提及中获取用户 ID:

Use a converter to get the User object:

@bot.command(name="id")
async def id_(ctx,user: discord.User):
    await ctx.send(user.id)

来自这篇文章:How to get ID of a mentioned user (Discord.py)