首页 > 解决方案 > Visual Studio 代码中的 Discord 未定义错误。我可以做些什么来修复我的代码?

问题描述

基本上机器人不会打开,每次我进入 node 。进入终端我得到这个错误:ReferenceError: discord is not defined at Object. (C:\Users\Izzabell\Downloads\discord-bot\index.js:1:23) 在 Module._compile (internal/modules/cjs/loader.js:1138:30) 在 Object.Module._extensions..js (internal/modules/cjs/loader.js:1158:10) 在 Module.load (internal/modules/cjs/loader.js:986:32) 在 Function.Module._load (internal/modules/cjs/loader.js :879:14) 在 Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12) 在 internal/main/run_main_module.js:17:47

如果有人可以提供帮助,这是一个屏幕截图和我使用的确切代码。

var Discord = require(discord.js);
var bot = new Discord.Client ();
const token = 'Enter token here';

bot.on('ready', () =>{    
   console.log('This bot is online!');
})

bot.on ('message', msg=>{
   if (msg.content === "boomer"){     
      msg.reply ('Im not a boomer >:(');
   }
})

bot.login(token);

[1]:https ://i.stack.imgur.com/aidrG.png我有一个代码截图的链接,我在这里复制并粘贴了代码。在屏幕截图中,被屏蔽的区域是我的令牌,我将输入令牌放在这里令牌应该去的地方。在实际代码中,插入了正确的令牌。

标签: visual-studio-code

解决方案


var Discord = require('discord.js'); 确保在 require 中添加两个 '


推荐阅读