python - Discord.py 向用户发送 dm
问题描述
所以我为我的机器人做了一个 dm 命令,它运行良好,但我不能 dm 用户名中有空格的用户。有谁知道如何做到这一点?
@client.command(pass_context=True)
@commands.is_owner()
async def dm(ctx, user: discord.User, *, message=None):
message = message or "Message from bot owner"
embed = discord.Embed(title="Message from bot owner", description=message, color = 0)
await user.send(embed = embed)
例如,当我试图用空格对用户进行 dm 操作时:=dm Special user#1234
我的终端说找不到用户 Special。
解决方案
你可以做
@client.command(pass_context=True)
@commands.is_owner()
async def dm(ctx, user, *, message=None):
if message is None:
await ctx.send("You need to specify the message to send!")
return
user = client.fetch_user(user)
await user.send(embed=discord.Embed(title="Message from bot owner", description=message, color = 0))
推荐阅读
- visual-studio - 如何在 Visual Studio 2019 中始终显示 F# 类型(如 VSCode)?
- python-3.x - sklearn.metrics.ConfusionMatrixDisplay 使用科学计数法
- javascript - 在 window.open() 中使用 windowName
- r - 如何在 flexdashboard 中删除或隐藏此输出窗口?
- c# - 如何根据 Unity 的文件夹结构设置命名空间
- jquery - 禁用基于 Radio selected 的 SELECT 选项不适用于 jquery 3.4.1
- javascript - 如何将结果从猫鼬分组为较小的子数组
- python - pyspark matplotlib 与 Zeppelin 的集成
- javascript - 如何在 Flow 中正确输入渲染道具?
- python - 为 python smtplib 获取“网络无法访问”