Javascript 运行节点时出现此错误。为了我的discord.js机器人
这是我尝试运行节点时出现的错误 ** ** 这是我的index.jsJavascript 运行节点时出现此错误。为了我的discord.js机器人,javascript,discord.js,Javascript,Discord.js,这是我尝试运行节点时出现的错误 ** ** 这是我的index.js require("dotenv").config(); const fs = require("fs"); const request = require("request"); const cheerio = require("cheerio"); const fetch = require("node-fetch"); co
require("dotenv").config();
const fs = require("fs");
const request = require("request");
const cheerio = require("cheerio");
const fetch = require("node-fetch");
const DBL = require("dblapi.js");
const Discord = require("discord.js");
const client = new Discord.Client();
const dbl = new DBL(process.env.DBL_TOKEN, client);
let prefix = ".";
// Firebase
const firebase = require("firebase/app");
const admin = require("firebase-admin");
admin.initializeApp({
credential: admin.credential.cert({
project_id: "roboliam-427c0",
private_key: process.env.FIREBASE_PRIVATE_KEY.replace(/\\n/g, "\n"),
client_email: process.env.FIREBASE_CLIENT_EMAIL,
}),
});
let db = admin.firestore();
client.commands = new Discord.Collection();
const commandFiles = fs
.readdirSync("./commands")
.filter((file) => file.endsWith(".js"));
for (const file of commandFiles) {
const command = require(`./commands/${file}`);
client.commands.set(command.name, command);
}
client.once("ready", () => {
console.log("RoboLiam is now online.");
let users;
let guilds;
client.users.cache.tap((coll) => (users = coll.size));
client.guilds.cache.tap((coll) => (guilds = coll.size));
const status = [
{
activity: ".help | @RoboLiam",
type: "WATCHING",
},
{
activity: `${users} users in ${guilds} servers.`,
type: "WATCHING",
},
{
activity: "With Code.",
type: "PLAYING",
},
{
activity: "Minecraft.",
type: "PLAYING",
},
{
activity: "Naruto.",
type: "WATCHING",
},
{
activity: "LoFi Music.",
type: "LISTENING",
},
{
activity: "Furry YouTubers.",
type: "WATCHING",
},
];
let random = status[Math.floor(Math.random() * Math.floor(status.length))];
client.user.setActivity(random.activity, {
type: random.type,
});
setInterval(async function () {
client.users.cache.tap((coll) => (users = coll.size));
client.guilds.cache.tap((coll) => (guilds = coll.size));
random = status[Math.floor(Math.random() * Math.floor(status.length))];
client.user.setActivity(random.activity, {
type: random.type,
});
}, 60000);
});
client.on("message", async (message) => {
let doc;
if (message.guild) {
doc = message.guild.id;
} else {
doc = "NULL";
}
try {
await db
.collection("guilds")
.doc(doc)
.get()
.then((q) => {
if (q.exists) {
prefix = q.data().prefix;
} else {
prefix = ".";
}
});
} catch (e) {
console.error(e);
}
if (
message.content == `<@${client.user.id}>` ||
message.content == `<@!${client.user.id}>`
)
return message.channel.send(`The prefix is \`${prefix}\`.`);
if (!message.content.startsWith(prefix) || message.author.bot) return;
const args = message.content.slice(prefix.length).trim().split(/ +/);
const commandName = args.shift().toLowerCase();
const command =
client.commands.get(commandName) ||
client.commands.find(
(cmd) => cmd.aliases && cmd.aliases.includes(commandName)
);
if (!command) return;
if (command.guildOnly && message.channel.type !== "text") {
return message.reply("I can't execute that command inside DMs!");
}
if (command.args && !args.length) {
let reply = `You didn't provide any arguments!`;
if (command.usage) {
reply += `\nThe proper usage would be: \`${prefix}${command.name} ${command.usage}\``;
}
return message.reply(reply);
}
if (command.permission) {
if (
!message.guild.member(message.author).hasPermission(command.permission)
) {
return message.reply(
`You don't have permission to do that!\nYou need to be able to \`${command.permission}\` to run this command.`
);
}
}
try {
command.execute(message, args, db);
} catch (error) {
console.error(error);
message.reply("There was an error executing that command!");
}
});
client.on("guildCreate", async (gData) => {
db.collection("guilds").doc(gData.id).set({
guildID: gData.id,
prefix: ".",
});
});
client.login(process.env.BOT_TOKEN);
require(“dotenv”).config();
常数fs=要求(“fs”);
常量请求=要求(“请求”);
const cheerio=需要(“cheerio”);
const fetch=require(“节点获取”);
const DBL=require(“dblapi.js”);
const Discord=require(“Discord.js”);
const client=new Discord.client();
const dbl=新的dbl(process.env.dbl_令牌,客户端);
让前缀“=”;
//火基
const firebase=require(“firebase/app”);
const admin=require(“firebase管理员”);
admin.initializeApp({
凭证:admin.credential.cert({
项目编号:“roboliam-427c0”,
私钥:process.env.FIREBASE\u private\u key.replace(/\\n/g,“\n”),
客户电子邮件:process.env.FIREBASE客户电子邮件,
}),
});
设db=admin.firestore();
client.commands=new Discord.Collection();
const commandFiles=fs
.readdirSync(“./命令”)
.filter((file)=>file.endsWith(“.js”);
for(命令文件的常量文件){
const command=require(`./commands/${file}`);
client.commands.set(command.name,command);
}
client.once(“就绪”,()=>{
log(“RoboLiam现在在线了。”);
让用户;
让公会;
client.users.cache.tap((coll)=>(users=coll.size));
client.guilds.cache.tap((coll)=>(guilds=coll.size));
常数状态=[
{
活动:“.help |@RoboLiam”,
键入:“观看”,
},
{
活动:`{guilds}服务器中的${users}用户。`,
键入:“观看”,
},
{
活动:“带代码。”,
类型:“播放”,
},
{
活动:“地雷船”,
类型:“播放”,
},
{
活动:“鸣人”,
键入:“观看”,
},
{
活动:“洛菲音乐”,
键入:“正在听”,
},
{
活动:“毛茸茸的年轻人。”,
键入:“观看”,
},
];
让random=status[Math.floor(Math.random()*Math.floor(status.length));
client.user.setActivity(random.activity{
type:random.type,
});
setInterval(异步函数(){
client.users.cache.tap((coll)=>(users=coll.size));
client.guilds.cache.tap((coll)=>(guilds=coll.size));
random=status[Math.floor(Math.random()*Math.floor(status.length));
client.user.setActivity(random.activity{
type:random.type,
});
}, 60000);
});
client.on(“message”,异步(message)=>{
让医生;
if(message.guild){
doc=message.guild.id;
}否则{
doc=“NULL”;
}
试一试{
等待数据库
.收藏(“公会”)
.doc(doc)
.get()
。然后((q)=>{
如果(q.exists){
prefix=q.data().prefix;
}否则{
前缀=“.”;
}
});
}捕获(e){
控制台错误(e);
}
如果(
message.content==`||
message.content==``
)
返回message.channel.send(`前缀为\`${prefix}\`.`);
如果(!message.content.startsWith(prefix)| | message.author.bot)返回;
const args=message.content.slice(prefix.length.trim().split(+/);
const commandName=args.shift().toLowerCase();
常量命令=
client.commands.get(commandName)||
client.commands.find(
(cmd)=>cmd.aliases&&cmd.aliases.includes(commandName)
);
如果(!命令)返回;
if(command.guildOnly&&message.channel.type!=“text”){
返回message.reply(“我无法在DMs内执行该命令!”);
}
if(command.args&&!args.length){
let reply=`您没有提供任何参数!`;
if(命令用法){
reply+=`\n正确的用法是:\`${prefix}${command.name}${command.usage}\`;
}
返回消息。回复(reply);
}
if(命令权限){
如果(
!message.guild.member(message.author).hasPermission(command.permission)
) {
返回消息。回复(
`您没有执行此操作的权限!\n您需要能够\`command.permission}`运行此命令`
);
}
}
试一试{
执行命令(消息、参数、数据库);
}捕获(错误){
控制台错误(error);
reply(“执行该命令时出错!”);
}
});
client.on(“guildCreate”,异步(gData)=>{
db.collection(“guilds”).doc(gData.id).set({
Guidid:gData.id,
前缀:“.”,
});
});
client.login(process.env.BOT_令牌);
我尝试删除package-lock.json文件和节点模块,并重新安装了模块,但也出现了相同的错误,谢谢您的帮助。
我试着重新查看index.js文件,但没有得到任何想法,因此如果您帮助我(^-^),这将是一个很大的帮助。而不是运行
节点。
只需运行节点索引\u文件名
在您的情况下,您将运行
节点index.js
,因为index.js是您的条目文件(首先运行的那个)如何验证?我完全不明白,如果您帮助我编辑该文件,这将是一个很大的帮助?我已经添加了确保您的package.json有一个主文件条目,一个名为index.js节点。
运行由package.json
指示的主文件,在本例中,该文件看起来是index.js
。也许他的文件命名错误,或者不在正确的目录中?
require("dotenv").config();
const fs = require("fs");
const request = require("request");
const cheerio = require("cheerio");
const fetch = require("node-fetch");
const DBL = require("dblapi.js");
const Discord = require("discord.js");
const client = new Discord.Client();
const dbl = new DBL(process.env.DBL_TOKEN, client);
let prefix = ".";
// Firebase
const firebase = require("firebase/app");
const admin = require("firebase-admin");
admin.initializeApp({
credential: admin.credential.cert({
project_id: "roboliam-427c0",
private_key: process.env.FIREBASE_PRIVATE_KEY.replace(/\\n/g, "\n"),
client_email: process.env.FIREBASE_CLIENT_EMAIL,
}),
});
let db = admin.firestore();
client.commands = new Discord.Collection();
const commandFiles = fs
.readdirSync("./commands")
.filter((file) => file.endsWith(".js"));
for (const file of commandFiles) {
const command = require(`./commands/${file}`);
client.commands.set(command.name, command);
}
client.once("ready", () => {
console.log("RoboLiam is now online.");
let users;
let guilds;
client.users.cache.tap((coll) => (users = coll.size));
client.guilds.cache.tap((coll) => (guilds = coll.size));
const status = [
{
activity: ".help | @RoboLiam",
type: "WATCHING",
},
{
activity: `${users} users in ${guilds} servers.`,
type: "WATCHING",
},
{
activity: "With Code.",
type: "PLAYING",
},
{
activity: "Minecraft.",
type: "PLAYING",
},
{
activity: "Naruto.",
type: "WATCHING",
},
{
activity: "LoFi Music.",
type: "LISTENING",
},
{
activity: "Furry YouTubers.",
type: "WATCHING",
},
];
let random = status[Math.floor(Math.random() * Math.floor(status.length))];
client.user.setActivity(random.activity, {
type: random.type,
});
setInterval(async function () {
client.users.cache.tap((coll) => (users = coll.size));
client.guilds.cache.tap((coll) => (guilds = coll.size));
random = status[Math.floor(Math.random() * Math.floor(status.length))];
client.user.setActivity(random.activity, {
type: random.type,
});
}, 60000);
});
client.on("message", async (message) => {
let doc;
if (message.guild) {
doc = message.guild.id;
} else {
doc = "NULL";
}
try {
await db
.collection("guilds")
.doc(doc)
.get()
.then((q) => {
if (q.exists) {
prefix = q.data().prefix;
} else {
prefix = ".";
}
});
} catch (e) {
console.error(e);
}
if (
message.content == `<@${client.user.id}>` ||
message.content == `<@!${client.user.id}>`
)
return message.channel.send(`The prefix is \`${prefix}\`.`);
if (!message.content.startsWith(prefix) || message.author.bot) return;
const args = message.content.slice(prefix.length).trim().split(/ +/);
const commandName = args.shift().toLowerCase();
const command =
client.commands.get(commandName) ||
client.commands.find(
(cmd) => cmd.aliases && cmd.aliases.includes(commandName)
);
if (!command) return;
if (command.guildOnly && message.channel.type !== "text") {
return message.reply("I can't execute that command inside DMs!");
}
if (command.args && !args.length) {
let reply = `You didn't provide any arguments!`;
if (command.usage) {
reply += `\nThe proper usage would be: \`${prefix}${command.name} ${command.usage}\``;
}
return message.reply(reply);
}
if (command.permission) {
if (
!message.guild.member(message.author).hasPermission(command.permission)
) {
return message.reply(
`You don't have permission to do that!\nYou need to be able to \`${command.permission}\` to run this command.`
);
}
}
try {
command.execute(message, args, db);
} catch (error) {
console.error(error);
message.reply("There was an error executing that command!");
}
});
client.on("guildCreate", async (gData) => {
db.collection("guilds").doc(gData.id).set({
guildID: gData.id,
prefix: ".",
});
});
client.login(process.env.BOT_TOKEN);