首页 > 解决方案 > Discord.Client 不是构造函数

问题描述

我正在使用 discord.js 12.3.0 webpack

到目前为止,这是我的代码

<script type="text/javascript">
    const Discord = ('https://raw.githubusercontent.com/discordjs/discord.js/webpack/discord.12.3.0.min.js');
      const client = new Discord.Client();
    
      client.on('message', message => {
    console.log(message.content);
      });
    
      client.login('. . .');
    </script>

我的目标是让网站显示机器人的所有信息,但我无法使用机器人登录。

这是我的错误:

index.html:12 Uncaught TypeError: Discord.Client is not a constructor
    at index.html:12
(anonymous) @ index.html:12

index.html:8 Cross-Origin Read Blocking (CORB) blocked cross-origin response https://raw.githubusercontent.com/discordjs/discord.js/webpack/discord.12.3.0.min.js with MIME type text/plain. See https://www.chromestatus.com/feature/5629709824032768 for more details.

标签: javascripthtmlwebpackdiscorddiscord.js

解决方案


这是CORS问题。尝试<script src="..."></script>


推荐阅读