如何使我的discord.py重写机器人向消息作者发送私人消息

时间:2019-05-01 10:50:53

标签: python python-3.x discord.py discord.py-rewrite

我为游戏的Discord服务器制作了Discord机器人。我正在使用discord.py重写版本,并且想向消息作者发送私人消息。

我在互联网上尝试了其他代码,其中包括一些“ @bot”代码,但始终会出现错误

  

“未定义名称“机器人””

如果我尝试send_message,它会说

  

“客户端对象没有属性'send_message'”

我的代码:

#I've tried this...

@bot.command(pass_context=True)
async def poke(ctx, message):
    await client.send_message(ctx.message.author, 'boop')

#but it comes up with the error "Name 'bot' is not defined" and stuff like that

例如,我想创建一个命令“!messageme”,如果用户执行该命令,我希望机器人将消息的“ <作者> ”私人消息说为“刚刚给您发消息!”。

如果Pierce#9255在服务器中执行该命令,则该漫游器应向其私人消息说“刚刚给您发消息!”。

2 个答案:

答案 0 :(得分:0)

您是否定义了机器人变量?如果没有,请执行以下操作:

bot = commands.Bot(command_prefix='!') # Just add your desired prefix there.

# sending dm
@bot.command()
async def poke(ctx):
    await ctx.author.send('boop!')

此外,如果您仍然感到困惑,则可以尝试以下本教程:-NiByO6h7Ck

答案 1 :(得分:0)

首先,您必须定义Bot。您将必须DM用户。

bot = commands.Bot(command_prefix='your_prefix')

@bot.command()
async def hello(ctx):
    user = ctx.author
    await user.send("Hello!")
相关问题