【问题标题】:Debugging JS for a bot为机器人调试 JS
【发布时间】:2021-04-06 11:19:32
【问题描述】:

我开始使用 Visual Studio Code 编写 JS 代码。我是一个完全的初学者,这是我的问题。我做错了什么?

const Discord = require("discord.js");

const client = new Discord.Client;

Client.on("ready", () => {
    console.log("bot opérationnel");
});   

Client.login("MyTokenBot");

我在调试控制台上收到这条消息:

未捕获的引用错误:未定义客户端
没有可用的调试器,无法发送“变量”
进程以代码 1 退出

感谢您的帮助

【问题讨论】:

  • 确保在调用类的新实例时将括号添加到末尾:const client = new Discord.Client()
  • 欢迎来到 SO !请看我的回答,如果有帮助,请告诉我 - 如果有,请接受正确答案 - 干杯!

标签: node.js discord bots


【解决方案1】:

Client 未定义,因为您定义了 client(小 c)。 所以这应该有效:

const Discord = require("discord.js");

// const client = new Discord.Client;
const client = new Discord.Client();

client.on("ready", () => {
    console.log("bot opérationnel");
});   

client.login("MyTokenBot");

也很确定,如果你创建一个类的新实例,你也需要调用该方法,所以不要使用new Discord.Client,而是使用new Discord.Client()

【讨论】:

  • 哦不,我们的答案几乎是重复的。我会删除我的,因为你提前 3 秒回答了
  • 我猜我们几乎同时点击了“添加答案”:D
  • 几乎,您的请求提前 3 秒完成。我会删除我的答案
猜你喜欢
  • 1970-01-01
  • 2017-12-05
  • 2012-10-23
  • 1970-01-01
  • 2014-11-20
  • 2017-12-23
  • 2016-05-23
  • 1970-01-01
  • 2020-08-28
相关资源
最近更新 更多