【问题标题】:How to make discord bot automatically send direct message [Discord.py]如何使不和谐机器人自动发送直接消息[Discord.py]
【发布时间】:2021-03-25 22:03:34
【问题描述】:

如果我输入一些内容来触发事件,我可以通过 discord bot 发送直接消息。但是我不知道如何让discord bot在满足特定条件时自动发送直接消息

【问题讨论】:

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


    【解决方案1】:

    这是我的查询代码:

    要使其按命令发送,请执行以下操作:

    @bot.command()
    async def dm(ctx):
        await ctx.author.send("Hello, this is a DM!")
    

    然后让它在 on_message 触发器上发送:

    @bot.event
    async def on_message(message):
        if "dm" == message.content.lower()
            await message.author.send("Hello, this is a DM!")
    

    发生的事情是发送dm,向作者发送消息。就这么简单。但是对于 on_message,我们会检查消息是否为“dm”,在这种情况下,它就是你。

    【讨论】:

      【解决方案2】:

      您将首先设置您的机器人并让它运行。一个例子是

      @bot.event
      async def on_message(message):
          if "this triggers" in message.content:
              await message.author.send("I just dmed you this message")
      

      要检查它是否在公会中,message.guild != None 将返回 Truemessage.guild.id == 1232131231231 将检查公会/服务器的 id 是否为 1232131231231

      【讨论】:

      • 我觉得你需要awaitauthor.send
      猜你喜欢
      • 2021-08-07
      • 2021-05-30
      • 2018-01-13
      • 1970-01-01
      • 1970-01-01
      • 2022-11-02
      • 2021-04-03
      • 2020-12-26
      • 2019-12-10
      相关资源
      最近更新 更多