【问题标题】:FORBIDDEN (status code: 403) Can't send messages to this userFORBIDDEN(状态码:403)无法向该用户发送消息
【发布时间】:2018-11-05 21:28:48
【问题描述】:

我想做一个命令,将 DM 发送到整个服务器,但我收到以下错误:

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

这可能是什么原因?

这是我当前的代码:

@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)

【问题讨论】:

  • 用户可能已经阻止了你的机器人或禁用了服务器的 DM,只要发现错误,删除它并继续。
  • 我该怎么做?蛇

标签: python python-3.x discord discord.py


【解决方案1】:

用户可能已经阻止了您的机器人或为您的服务器禁用了 DM,无论哪种方式,您都无法挽救这种情况,因此只需放弃异常即可。

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

【讨论】:

  • 你应该抓住discord.Forbidden,而不是更笼统(也不太具体)的Exception
猜你喜欢
  • 1970-01-01
  • 2020-02-17
  • 2020-10-01
  • 2018-12-26
  • 2020-12-20
  • 2021-11-06
  • 2021-05-29
  • 2020-06-04
  • 2020-09-24
相关资源
最近更新 更多