【问题标题】:Send a DM to all the members of a server discord.py向服务器 discord.py 的所有成员发送 DM
【发布时间】:2021-10-23 18:49:33
【问题描述】:

我正在尝试向服务器的所有成员发送 dm。我正在使用的代码没有错误,但它不起作用。

@bot.command(pass_context=True)
async def dm(ctx, *, message):
        for user in ctx.guild.members:
            try:
                await user.send(message)
                print(f"Sent {user.name} a DM.")
            except:
                print(f"Couldn't DM {user.name}.")
        print("Sent all the server a DM.")

【问题讨论】:

  • 您能否将except 替换为except Exception as e: print(e) 并发布输出?另外 - 您是否设置了所需的意图?
  • 我更换了,它是 sintax 错误
  • 我想这不言自明
  • 好的,现在可以了。输出:400 Bad Request(错误代码:50007):无法向该用户发送消息
  • 是的,这可能是机器人本身,您不能向自己发送 DM。您是否设置了必要的意图?

标签: python discord discord.py bots


【解决方案1】:

我知道这已经得到了回答,但对于将来看到这个的人来说:

  • 确保您的机器人的意图允许它访问成员
  • 另外请记住,某些成员关闭了 DM(来自服务器成员的 DM)

希望这会有所帮助

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-01-18
    • 2021-12-02
    • 1970-01-01
    • 2021-08-03
    • 1970-01-01
    • 2021-01-06
    • 2022-01-11
    • 1970-01-01
    相关资源
    最近更新 更多