python - Discord.py 重写如何DM命令?

标签 python python-3.x discord.py

我试图让我的机器人在执行“-help”时向用户发送帮助。

我已经尝试在我的代码中执行此操作,但它不起作用。

async def help(ctx):
  helpembed = discord.Embed(color=discord.Color.purple())
  helpembed.set_author(name="Help")
  helpembed.add_field(name="-new", value="Creates a new ticket. [Logged]",inline=False)
  helpembed.add_field(name="-close", value="Closes the ticket.People with the role 'Viewing Team' can close ticets. [Logged]",inline=False)
  helpembed.add_field(name="-setup", value='Sets Up your server so it can be used',inline=False)
  helpembed.add_field(name="-help", value="Shows this message :rofl:",inline=False)
  await client.send_message(ctx.message.author, embed=helpembed)
await ctx.send("Help sent in DM's.")```

The bot should DM the user with help. Instead it does nothing.

最佳答案

中的用户发送私有(private)消息,您使用 User.send方法:

async def help(ctx):
    ...
    await ctx.author.send(...)

这是因为 User 是抽象 Messageable 的子类类

关于python - Discord.py 重写如何DM命令?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55895117/

相关文章:

python - 合并排序递归错误

python - 我可以通过更改算法来增加随机性吗?

python - Dataframe pandas 中的 POS 标记-Textblog

python-3.x - 导入 rpy2.ipython 遇到错误 ModuleNotFoundError : No module named 'IPython'

python-3.x - 将大型数据集加载/feed_dicting 到 Tensorflow session 中

linux - 修复 AttributeError : 'file' object has no attribute 'buffer' (Python3)

python - 如何使用新的 Discord.py 版本获取 Discord 服务器中所有成员的列表?

python - git Push azure master azure fatal : Not a git repository (or any of the parent directories): . git

heroku - discord.py Heroku FFmpeg 问题

python - 能否查看语音 channel 是否有用户?