问题
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