问题描述
我试图让我的机器人在执行-help"时向用户发送帮助.
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.
推荐答案
向discord.py-rewrite,你使用 user.send 方法:
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(...)
这是因为 user 是抽象 messageable 类
this is because user is a subclass of the abstract messageable class