【问题标题】:Discord not defined error in visual studio code. What can I do to fix my code?Visual Studio 代码中的 Discord 未定义错误。我可以做些什么来修复我的代码?
【发布时间】:2020-11-08 10:15:28
【问题描述】:

基本上机器人不会打开,每次我进入 node 。进入终端我得到这个错误:ReferenceError: discord is not defined 在对象。 (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


    【解决方案1】:

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

    【讨论】:

    • 我明天试试。晚了。我会告诉你它是否有效。
    • 好的,这是代码中的错误,但问题与 discord.js 有关。我以为它已下载但我重新下载并重新编写了代码并且它工作。我不知道我做了什么。哈哈。泰寻求帮助。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-30
    • 2017-08-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多