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

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

问题描述

我正在尝试让我的机器人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.


推荐答案

中的用户发送私人消息href = / questions / tagged / discord.py-rewrite class = post-tag title =显示被标记为'discord.py-rewrite' rel = tag> 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 是抽象 可发消息的

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

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

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