Discord.py rewrite How to DM commands?

我的未来我决定 提交于 2019-12-11 04:58:49

问题


I am trying to have my bot DM the user the help when "-help" is executed.

I have tried doing this in my code already but it will not work.

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.

回答1:


To send a private message to a user in discord.py-rewrite, you use the User.send method:

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

This is because User is a subclass of the abstract Messageable class



来源:https://stackoverflow.com/questions/55895117/discord-py-rewrite-how-to-dm-commands

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!