我一直试图使我的机器人在Discord上上线,但出现此错误,并且不知道如何解决:
此外,这是“ package.json”文件:
{
"name": "botName",
"version": "1.0.0",
"main": "raidBot.js",
"scripts": {
"text": "echo \"Error: no test specified\" && exit 1"
},
"author": "uwu || dm 2 partner#7245 & lottie#8696",
"license": "ISC",
"dependencies": {
"discord.js": "^11.4.2"
},
"description": ""
}
“ botName.js”文件:
const discord = require('discord.js');
var client = new discord.Client();
const token = "instertedTokenHere";
client.on ("ready", () => {
console.log("the bot is ready...");
client.user.setGame ("prefix is $");
});
const prefix = "$";
client.on ("message"), (message) => {
if (message.author.bot) return;
if (message.content.startsWith (prefix + "bot")) {
message.reply ('Running...');
}
};
注意::这是导致错误的原因:
cd D:\bot004
npm install
npm install --save discord.js
node .
一切似乎都很好。我有node_modules
文件夹以及package.json
,package-lock.json
和botName.js
文件。
答案 0 :(得分:0)
将客户变量放在令牌下。制作不和谐的机器人时,我遇到了同样的错误。
答案 1 :(得分:0)
// Your code
const discord = require('discord.js');
var client = new discord.Client();
const token = "instertedTokenHere";
client.on ("ready", () => {
console.log("the bot is ready...");
client.user.setGame ("prefix is $");
});
const prefix = "$";
client.on ("message"), (message) => {
if (message.author.bot) return;
if (message.content.startsWith (prefix + "bot")) {
message.reply ('Running...');
}
};
这看起来有点可疑。您没有将回调函数传递给下面的.on()
方法。这就是您的错误出处。
client.on ("message"), (message) => {
if (message.author.bot) return;
if (message.content.startsWith (prefix + "bot")) {
message.reply ('Running...');
}
};
尝试对此进行重构:
client.on ("message", (message) => {
if (message.author.bot) return;
if (message.content.startsWith (prefix + "bot")) {
message.reply ('Running...');
}
});
按原样运行代码时,我能够重现该错误。修复代码后,错误消失了。