缺少权限:找不到原因:discord.js

时间:2020-09-01 05:23:38

标签: javascript node.js discord discord.js

因此,当我启动bot几分钟后,它开始在控制台中出现错误,并且似乎找不到导致我的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);

编辑:看来已经解决了这个问题,但是现在我又遇到了另一个问题:

它说无法读取未定义的bot的属性,但是 我只定义了客户端,没有使用机器人。

1 个答案:

答案 0 :(得分:0)

首先,您必须减少侦听器的数量(这意味着client.onclient.once),这会令人难以置信地降低API的速度,但同时也很杂乱,并且常常会导致错误。使用每个监听器一次

如果您缺少权限错误,则表示您的漫游器缺少执行操作的权限,请确保在实际执行操作之前检查执行操作所需的权限。您可以使用message.guild.me.hasPermission(<permission here>)