【问题标题】:How do I send a direct message to someone when they join a server with discord.py当某人使用 discord.py 加入服务器时,如何向他们发送直接消息
【发布时间】:2017-11-13 22:03:27
【问题描述】:

我正在为我的 discord 服务器编写一个机器人,我想向第一次加入服务器的任何人发送一条自动直接消息。我查看了文档,但找不到任何有关如何执行此操作的信息。我正在使用 python 3.5 和 discord.py 版本 0.16.12。

【问题讨论】:

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


    【解决方案1】:

    如果您使用 discord py rewrite,这应该可以工作 确保您已为机器人启用意图,如图所示

    intents=discord.Intents.all()
    client = commands.Bot(command_prefix= cmd,intents=intents)
    @client.event
    async def on_member_join(member):
        await member.send(f"your welcome message here")
    

    【讨论】:

      【解决方案2】:

      https://discordpy.readthedocs.io/en/latest/api.html#discord.on_member_join

      您可以按照以下方式做一些事情:

      await bot.send_message(member, "hello")
      

      【讨论】:

      • 完美运行!谢谢!
      猜你喜欢
      • 2021-01-09
      • 2021-06-10
      • 2021-08-03
      • 2018-07-27
      • 2021-08-22
      • 2021-03-19
      • 2021-11-12
      • 2020-11-19
      • 2020-12-05
      相关资源
      最近更新 更多