I am able to get the bot to direct message anyone with a specific role using the following code:
@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)
However, when I try to make the bot dm all users in my server, only I receive a message. This is the code I used:
@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)
When checking the output window, I get the error:
"Forbidden: FORBIDDEN (status code: 403): Cannot send messages to this user"
*Please note that there are various imports and variables defined outside of the code snippets shown here.
Any pointers as to where I am going wrong would be very much appreciated.