【发布时间】:2021-05-26 21:02:33
【问题描述】:
所以我正在尝试开始学习如何编写 Discord 机器人。 但是当我运行代码并说命令“!hello” 它只是说这个错误信息:
Uncaught ReferenceError: hello is not defined 没有可用的调试器,无法发送“变量” 进程以代码 1 退出
我该如何解决?
const { Client, MessageAttachment } = require("discord.js");
const bot = new Client();
const token = new String("")
bot.on('ready', () =>{
console.log("I am online!");
})
bot.on('message', (message) =>{
console.log("HELLO");
if(message.author.bot) return;
let prefix = '!';
let MessageArray = message.content.split(' ');
let cmd = MessageArray[0].slice(prefix.length);
let args = MessageArray.slice(1);
if(!message.content.startsWith(prefix)) return;
//command
if(cmd === hello){
console.log("command sent");
message.channel.send("Hello there!");
}
})
bot.login(token censored)
【问题讨论】:
-
缺少引号,应该是
cmd === 'hello'。没有hello变量。 -
我意识到我忘记了顶部。我已经放了“const { Client, MessageAttachment } = require("discord.js")”
标签: javascript discord discord.js