Python Discord.py:禁止403,无法向用户发送消息-如何让我的bot迭代并dm服务器中的所有成员?

Python Discord.py:禁止403,无法向用户发送消息-如何让我的bot迭代并dm服务器中的所有成员?,python,discord,discord.py,Python,Discord,Discord.py,我可以使用以下代码让bot直接向具有特定角色的任何人发送消息: @bot.command(pass_context=True) @commands.has_any_role(roleCheck) async def dmrole(ctx, role: discord.Role, *, message): for member in ctx.message.server.members: if role in member.roles: await

我可以使用以下代码让bot直接向具有特定角色的任何人发送消息:

@bot.command(pass_context=True)
@commands.has_any_role(roleCheck)
async def dmrole(ctx, role: discord.Role, *, message):
    for member in ctx.message.server.members:
        if role in member.roles:
            await bot.send_message(member, message)
但是,当我尝试使bot dm成为我服务器中的所有用户时,只有我收到一条消息。这是我使用的代码:

@bot.command(pass_context=True)
@commands.has_any_role(roleCheck)
async def dmall(ctx,*, message):
    for member in ctx.message.server.members:
        await bot.send_message(member, message)
检查输出窗口时,我得到错误:

“禁止:禁止(状态代码:403):无法向此服务器发送消息 用户“

*请注意,在这里显示的代码段之外定义了各种导入和变量


任何关于我错在哪里的指点都将不胜感激

因此,我发现只要捕获并传递异常就可以修复错误。谢谢你的帮助

您的bot可能缺少向用户发送消息所需的权限。它有“管理角色”权限吗?是的,我给了它管理员权限,并确保它不是一个权限问题,这是一个非常好的主意。将尝试。如果您尝试向非好友禁用DMs的用户发送禁止的消息,您将遇到禁止。这不是权限问题。