Discord.py rewrite 如何 DM 命令? [英] Discord.py rewrite How to DM commands?

查看:17
本文介绍了Discord.py rewrite 如何 DM 命令?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让我的机器人在执行-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.

推荐答案

,你使用 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

这篇关于Discord.py rewrite 如何 DM 命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆