FORBIDDEN (status code: 403) Can't send messag

2019-01-20 17:40发布

问题:

I want to make a command that will send a DM to the entire server, but I am getting the following error:

Forbidden: FORBIDDEN (status code: 403) Can't send messages to this user

What might be causing this?

Here is my current code:

@bot.command(pass_context=True)
async def massdm(ctx, words*):
    output = " "
    for word in words:
        output += word
        output += "" 
    server = ctx.message.server
    for member in server.members:
        await bot.send_message(member, output)

回答1:

The user might have blocked your bot or disabled DMs for your server, either way, you won’t be able to salvage the situation, so simply dropping the exception will do.

try:
  /* send message */
except Exception: 
  pass