我正在使用discord.js对Discord机器人进行编程。我希望该机器人在浏览器环境中运行。我的应用程序可以按预期在本地与Discord API进行通信,但是如果我发布它并从我的公共领域(例如, http://myapp.example.com/
,它不起作用并显示以下消息:
Access to fetch at 'https://discordapp.com/api/v7/gateway' from origin 'http://myapp.example.com/' has been blocked by CORS policy: The 'Access-Control-Allow-Origin' header has a value 'null' that is not equal to the supplied origin. Have the server send the header with a valid value, or, if an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
我了解什么是CORS政策以及为什么它阻止了我。有没有一种方法可以将Discord配置为接受来自指定来源的请求?