首页 > 解决方案 > 向服务器 discord.py 的所有成员发送 DM

问题描述

我正在尝试向服务器的所有成员发送 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.")

标签: pythondiscorddiscord.pybots

解决方案


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

  • 确保您的机器人的意图允许它访问成员
  • 还要记住一些成员关闭了 DM(来自服务器成员的 dms)

希望这会有所帮助


推荐阅读