【发布时间】:2022-01-10 05:55:30
【问题描述】:
所以几分钟后,当我启动我的机器人时,它开始在我的控制台中出现错误,我似乎无法在我的 index.js 文件中找到导致该错误的部分。我怀疑它在 index.js 文件中,因为它在启动几分钟后开始
我的 index.js 文件:
const fs = require('fs');
const Discord = require('discord.js');
const { prefix, token, blacklist } = require('./config.json');
const fetch = require('node-fetch');
const alexa = require('alexa-bot-api')
const winston = require('winston');
const DBL = require("dblapi.js");
const express = require('express');
const keepAlive = require('./server.js');
var chatbot = new alexa("aw2plm")
const client = new Discord.Client();
const server = express();
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);
}
const cooldowns = new Discord.Collection();
const dbl = new DBL(process.env.TOKEN, client,);
client.once('ready', () => {
client.user.setActivity(`with .help in || ${client.guilds.cache.size} || servers `);
});
dbl.on('posted', () => {
console.log('Server count posted!');
})
const logger = winston.createLogger({
transports: [
new winston.transports.Console(),
new winston.transports.File({ filename: 'log' }),
],
format: winston.format.printf(log => `[${log.level.toUpperCase()}] - ${log.message}`),
});
client.on('ready', () => logger.log('info', `${client.user.tag} has logged in.`));
client.on('debug', m => logger.log('debug', m));
client.on('warn', m => logger.log('warn', m));
client.on('error', m => logger.log('error', m));
process.on('uncaughtException', error => logger.log('error', error));
client.on('message', async message => {
if (message.author.bot) return;
if (message.channel.name == "axix-talks") {
let content = message.content;
message.channel.startTyping();
chatbot.getReply(content).then(r => message.channel.send(`**${message.author.username}** >> ${r}`)).then(message.channel.stopTyping())
}
});
client.once('ready', () => {
client.channels.cache.get("738646718865735691").setName(`BOT-STATUS :- ONLINE`);
});
client.on('disconnect', () => {
client.channels.cache.get("738646718865735691").setName(`BOT-STATUS :- OFFLINE`);
});
client.on('message', async message => {
if (message.author.bot) return;
if (message.channel.name == "dum-talks") {
let content = message.content;
message.channel.startTyping();
chatbot.getReply(content).then(r => message.channel.send(`**${message.author.username}** >> ${r}`)).then(message.channel.stopTyping())
}
});
client.on('message', async message => {
if (message.author.bot) return;
if (message.channel.name == "axix-talks-nsfw") {
if(!message.channel.nsfw) return;
let content = message.content;
message.channel.startTyping();
chatbot.getReply(content).then(r => message.channel.send(`**${message.author.username}** >> ${r}`)).then(message.channel.stopTyping())
}
});
client.on('message', async message => {
if (message.author.bot) return;
if (message.channel.type == "dm") {
let content = message.content;
message.channel.startTyping();
chatbot.getReply(content).then(r => message.channel.send(`**${message.author.username}** >> ${r}`)).then(message.channel.stopTyping())
}
});
client.on('message', message => {
if (message.author.bot) return;
if (message.mentions.has(client.user)) {
message.channel.send('Hi my prefix is >> \`.\` use this with \`help\` to get my command list')
}
});
client.on('guildCreate', guild => {
const examplembed = new Discord.MessageEmbed()
.setColor(0x00AE86)
.setTitle(`LOGS #${client.guilds.cache.size} >> I JOINED THE SERVER >> ${guild.name} <<`)
.setThumbnail(guild.iconURL)
.addField(':arrow_right: Name', guild.name, true)
.addField(':arrow_left: ID', guild.id, true)
.addField(':arrow_right: Region', guild.region)
.addField(':arrow_right: Member Count', guild.memberCount)
.addField(':arrow_left: Owner', guild.owner.user.tag)
.setTimestamp()
.setFooter(`AXix LOGS`)
client.channels.cache.get('726303011147612270').send(examplembed);
});
client.on('guildCreate', guild => {
client.user.setActivity(`with .help in || ${client.guilds.cache.size} || servers `);
client.channels.cache.get("738616235289346139").setName(`BOT-GUILDS :- ${client.guilds.cache.size}`);
client.channels.cache.get("742295489411809400").setName(`SERVER :- ${guild.name}`);
client.channels.cache.get("742296590349238293").setName(`BY :- ${guild.owner.user.tag}`);
client.channels.cache.get("738617153787265126").setName(`BOT-USERS :- ${client.users.cache.filter(member => !member.user.bot).size}`);
client.channels.cache.get("738623887679553666").setName(`BOT-PREFIX :- :- ${config.prefix}`);
});
client.on('guildCreate', guild => {
const examplembed = new Discord.MessageEmbed()
.setColor(0x00AE86)
.setTitle(`Here is guide for you on how to setup`)
.setThumbnail(guild.iconURL)
.addField(':arrow_right: CREATE CHANNELS NAMED :', '< axix-talks > or < axix-talks-nsfw > must be exact here is a tutorial:-https://youtu.be/07aJC6JrZ4w')
.addField(':arrow_left: NOW SAY :', 'HI')
.addField(':arrow_right: BOT DOES NOT REPLY', 'MAKE SURE YOU GOT THE CHANNEL NAMES RIGHT <IF ALL THE CHANNEL NAMES ARE CORRECT JOIN OUR DISCORD')
.addField(':arrow_right: DISCORD:', 'https://discord.gg/Q2YNZrC')
.addField(':arrow_left: BOTS RESPONSE IS LATE', 'BOTS RESPONSE IS LATE IS EXPECTED RIGHT NOW WE CANT DO ANYTHING ABOUT IT IT IS A API PORBLEM')
.addField(':arrow_right: WE DID NOT IMPLEMENT A ANTISWEAR BECUSE SOME SERVER OWNER LIKE TO KEEP IT NSFW IN NON NSFW MARKED CHANNELS', 'IF YOU WANT NSFW PROTECTION USE THIS BOT :https://top.gg/bot/522658556768419840 \nthis is not our bot this is only a suggestion')
.setTimestamp()
.setFooter(`axix guide`)
const channel = guild.channels.cache.find(c => c.id === guild.systemChannelID);
channel.send(examplembed);
channel.send(`@${guild.owner}`);
});
client.on('guildDelete', guild => {
client.user.setActivity(`with .help in || ${client.guilds.cache.size} || servers `);
const examplembed = new Discord.MessageEmbed()
.setColor(0x00AE86)
.setTitle(`LOGS #${client.guilds.cache.size} >> I left THE SERVER >> ${guild.name} <<`)
.setThumbnail(guild.iconURL)
.addField(':arrow_right: Name', guild.name, true)
.addField(':arrow_left: ID', guild.id, true)
.addField(':arrow_right: Region', guild.region)
.addField(':arrow_right: Member Count', guild.memberCount)
.addField(':arrow_left: Owner', guild.owner.user.tag)
.setTimestamp()
.setFooter(`axix LOGS`)
client.channels.cache.get('726303011147612270').send(examplembed);
});
client.on('guildDelete', guild => {
client.user.setActivity(`with .help in || ${client.guilds.cache.size} || servers `);
client.channels.cache.get("738616235289346139").setName(`BOT-GUILDS :- ${client.guilds.cache.size}`);
client.channels.cache.get("738617153787265126").setName(`BOT-USERS :- ${client.users.cache.filter(member => !member.user.bot).size}`);
client.channels.cache.get("738623887679553666").setName(`BOT-PREFIX :- :- ${config.prefix}`);
});
client.on('message', message => {
if (message.author.id === `${blacklist}`) return message.author.send("you are blacklisted from using the bot.mistake? conatct us on discord :https://discord.gg/6e9YMNJ");
if (!message.content.startsWith(prefix) || message.author.bot) return;
const args = message.content.slice(prefix.length).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, ${message.author}!`;
if (command.usage) {
reply += `\nThe proper usage would be: \`${prefix}${command.name} ${command.usage}\``;
}
return message.channel.send(reply);
}
if (!cooldowns.has(command.name)) {
cooldowns.set(command.name, new Discord.Collection());
}
const now = Date.now();
const timestamps = cooldowns.get(command.name);
const cooldownAmount = (command.cooldown || 3) * 1000;
if (timestamps.has(message.author.id)) {
const expirationTime = timestamps.get(message.author.id) + cooldownAmount;
if (now < expirationTime) {
const timeLeft = (expirationTime - now) / 1000;
return message.reply(`please wait ${timeLeft.toFixed(1)} more second(s) before reusing the \`${command.name}\` command.`);
}
}
timestamps.set(message.author.id, now);
setTimeout(() => timestamps.delete(message.author.id), cooldownAmount);
try {
command.execute(message, args);
} catch (error) {
console.error(error);
message.reply(`there was an error trying to execute that ERROR >>: ${error}`);
}
});
keepAlive();
client.login(process.env.CLIENT_TOKEN);
编辑:似乎已经解决了这个问题,但现在我遇到了另一个问题:
它的说法无法读取未定义的机器人的属性但是 我只定义了客户端,没有使用机器人。
【问题讨论】:
-
你能给出完整的错误吗?通常,它应该告诉您发生错误的行
-
是的,我想这样做。但它说只是在 discord.js 中缺少权限,其中有几行,但这可能是问题,因为我什至无法编辑它
-
现在出现丢失的烫发错误,而不是发生 bor 错误,当我可以编辑帖子时出现错误
标签: javascript node.js discord discord.js