我最近创建了一个只允许发送消息和读取消息历史记录的机器人。在我自己的服务器上,该机器人似乎可以完美运行,但某个用户尝试在他自己的服务器上使用该机器人并弹出错误 discord.errors.Forbidden: 403 FORBIDDEN (error code: 50013): Missing Permissions
。
await message.channel.send(file=discord.File(io.BytesIO(meme), filename="meme.png"))
上面的行是导致错误的原因。我在想我需要“附加文件”权限,但出于某种原因,它在我的测试服务器上没有它也能正常工作。
完整回溯:
Traceback (most recent call last):
File "/home/nemplayer/.local/lib/python3.7/site-packages/discord/client.py", line 270, in _run_event
await coro(*args, **kwargs)
File "bot/bot.py", line 78, in on_message
await message.channel.send(file=discord.File(io.BytesIO(meme), filename="meme.png"))
File "/home/nemplayer/.local/lib/python3.7/site-packages/discord/abc.py", line 806, in send
content=content, tts=tts, embed=embed, nonce=nonce)
File "/home/nemplayer/.local/lib/python3.7/site-packages/discord/http.py", line 218, in request
raise Forbidden(r, data)
discord.errors.Forbidden: 403 FORBIDDEN (error code: 50013): Missing Permissions
原文由 NemPlayer 发布,翻译遵循 CC BY-SA 4.0 许可协议
如您所说, 错误代码:50013 表示您无权执行该操作。
ATTACH_FILES
不是你必须拥有的唯一 权限,你可能还需要SEND_MESSAGES
和VIEW_CHANNEL
如果你也有 权限检查它们,它也是“隐含 的”。