【问题标题】:How to make my discord.py rewrite bot send a Private Message to the message author如何让我的 discord.py 重写机器人向消息作者发送私人消息
【发布时间】:2019-09-19 22:45:48
【问题描述】:

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

我尝试了互联网上的其他代码,其中包括一些“@bot”代码,但它总是出现错误

“名称'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 在服务器中执行命令,机器人应该私信他说“刚刚给你发了消息!”。

【问题讨论】:

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


【解决方案1】:

首先你必须定义Bot。您必须向用户发送 DM。

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

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

【讨论】:

    【解决方案2】:

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

    bot = commands.Bot(command_prefix='!') # Just add your desired prefix there.
    
    # sending dm
    @bot.command()
    async def poke(ctx):
        await ctx.author.send('boop!')
    

    另外,如果你仍然感到困惑,那么试试这个 yt 教程:-NiByO6h7Ck

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-01-03
      • 2021-03-19
      • 2012-09-21
      • 1970-01-01
      • 1970-01-01
      • 2021-04-09
      • 1970-01-01
      • 2021-01-26
      相关资源
      最近更新 更多