首页 > 解决方案 > Discord Bot 卡在“就绪”状态

问题描述

我的不和谐机器人目前没有启动它正在监视超过 10000 多个成员我的机器人将启动但它卡Ready在不和谐但它的状态是离线

我的 main.js

const https = require('https');

const url = 'https://www.reddit.com/r/meme/hot/.json?limit=100'

const aurl = 'https://www.reddit.com/r/aww/top/.json?sort=top&t=day&limit=100'





const Discord = require("discord.js");
const client = new Discord.Client();
const prefix = "$";
const fs = require('fs');
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 express = require("express")

const app = express()


app.get("/", (req, res) =>{
  console.log("helloe")
})

app.listen(3000, () => {
  console.log("Ready")
})
const disbut = require('discord-buttons');
disbut(client);



client.once('ready', () => {
    console.log('Beast Bot is ready');

     client.guilds.cache.forEach(guild => {
      console.log(`${guild.name} | ${guild.id}`);
   
    setInterval(() => {
      let server = client.guilds.cache.reduce((a, b) => a + b.memberCount, 0)
      client.user.setPresence({
        activity: {
          name: `${server} members || $help ||.`,
          type: "WATCHING"
        },
        status: "online"
      })
        
      
    }, 1500);
   
    })
});






client.on('clickButton', async(button) => {
  
  })

client.on("message", async message => {
  if (message.author.bot || !message.content.startsWith(prefix)) return;

  if (message.channel.type == "dm") return;
   
    
  const args = message.content.slice(prefix.length).trim().split(/ +/);
  const command = args.shift().toLowerCase();

  if(command === 'joke'){
    client.commands.get('joke').execute(message, args);
  }
  if(command === 'lock'){
    client.commands.get('lock').execute(message, args);
  }
  if(command === 'roast'){
    client.commands.get('roast').execute(message, args);
  }
  if(command === 'unlock'){
    client.commands.get('unlock').execute(message, args);
  }
  if(command === 'mute'){
    client.commands.get('mute').execute(message, args);
  }
  if(command === 'unmute'){
    client.commands.get('unmute').run(message, args);
  }
  if(command === 'clear'){
    client.commands.get('clear').execute(message, args);
  }
  if(command === 'advice'){
    client.commands.get('advice').execute(message, args);
  }
  if(command === 'neko'){
    client.commands.get('neko').execute(message, args);
  }
  if(command === 'fact'){
    client.commands.get('fact').execute(message, args);
  }
  if(command === 'animegif'){
    client.commands.get('animegif').execute(message, args);
  }
  if(command === 'topanimes'){
    client.commands.get('topanimes').execute(message, args);
  }
  if(command === 'status'){
    client.commands.get('mcstats').execute(message, args);
  }
    
    

   

  



  if(message.content.startsWith(prefix + 'nuke')){
  message.channel.send('Due to some bugs this command has been disabled for 5 days')
  
}
  
  

if (message.content.startsWith("$meme")) {

  https.get(url, (result) => {
    var body = ''
    result.on('data', (chunk) => {
        body += chunk
    })
  
    result.on('end', () => {
        var response = JSON.parse(body)
        var index = response.data.children[Math.floor(Math.random() * 99) + 1].data
  
        if (index.post_hint !== 'image') {
  
            var text = index.selftext
            const textembed = new Discord.MessageEmbed()
                .setTitle(subRedditName)
                .setColor(9384170)
                .setDescription(`[${title}](${link})\n\n${text}`)
                .setURL(`https://reddit.com/${subRedditName}`)
  
            message.channel.send(textembed)
        }
  
        var image = index.preview.images[0].source.url.replace('&', '&')
        var title = index.title
        var link = 'https://reddit.com' + index.permalink
        var subRedditName = index.subreddit_name_prefixed
  
        if (index.post_hint !== 'image') {
            const textembed = new Discord.MessageEmbed()
                .setTitle(subRedditName)
                .setColor(9384170)
                .setDescription(`[${title}](${link})\n\n${text}`)
                .setURL(`https://reddit.com/${subRedditName}`)
  
            message.channel.send(textembed)
        }
        console.log(image);
        const imageembed = new Discord.MessageEmbed()
            .setTitle(subRedditName)
            .setImage(image)
            .setColor(9384170)
            .setDescription(`[${title}](${link})`)
            .setURL(`https://reddit.com/${subRedditName}`)
        message.channel.send(imageembed)
    }).on('error', function (e) {
        console.log('Got an error: ', e)
    })
  })
    }





    if (message.content.startsWith("$cute")) {

      https.get(aurl, (result) => {
        var body = ''
        result.on('data', (chunk) => {
            body += chunk
        })
      
        result.on('end', () => {
            var response = JSON.parse(body)
            var index = response.data.children[Math.floor(Math.random() * 99) + 1].data
      
            if (index.post_hint !== 'image') {
      
                var text = index.selftext
                const textembed = new Discord.MessageEmbed()
                    .setTitle(subRedditName)
                    .setColor(9384170)
                    .setDescription(`[${title}](${link})\n\n${text}`)
                    .setURL(`https://reddit.com/${subRedditName}`)
      
                message.channel.send(textembed)
            }
      
            var image = index.preview.images[0].source.url.replace('&', '&')
            var title = index.title
            var link = 'https://reddit.com' + index.permalink
            var subRedditName = index.subreddit_name_prefixed
      
            if (index.post_hint !== 'image') {
                const textembed = new Discord.MessageEmbed()
                    .setTitle(subRedditName)
                    .setColor(9384170)
                    .setDescription(`[${title}](${link})\n\n${text}`)
                    .setURL(`https://reddit.com/${subRedditName}`)
      
                message.channel.send(textembed)
            }
            console.log(image);
            const imageembed = new Discord.MessageEmbed()
                .setTitle(subRedditName)
                .setImage(image)
                .setColor(9384170)
                .setDescription(`[${title}](${link})`)
                .setURL(`https://reddit.com/${subRedditName}`)
            message.channel.send(imageembed)
        }).on('error', function (e) {
            console.log('Got an error: ', e)
        })
      })
        }

    //download here

    if(message.content.startsWith("$download")){
    let button = new disbut.MessageButton()
  .setLabel("Download")
  .setURL('http://www.beaststudios.ga')
  .setStyle('url');

    //download end

message.channel.send("Download Firebones at www.beaststudios.ga", button);



        
        
    }

    if(message.content.startsWith("$invite")){
      let ibutton = new disbut.MessageButton()
    .setLabel("Invite")
    .setURL('https://discord.com/oauth2/authorize?client_id=876824416531664896&permissions=8&scope=bot')
    .setStyle('url');

    message.channel.send("Invite me to your server", ibutton);

    }
    
    
  if(message.content.startsWith("~mute")) {
    if(message.member.hasPermission("KICK_MEMBERS"))
    {
      message.reply(`Thanks for pinging my co-owner you will be banned with in 24 hours :))`);

    }
  };


  if (!message.guild) return;

  // if the message content starts with "!ban"
  if (message.content.startsWith('$ban')) {

    if (message.member.hasPermission("BAN_MEMBERS")) {
     // Assuming we mention someone in the message, this will return the user
    // Read more about mentions over at https://discord.js.org/#/docs/main/master/class/MessageMentions
    const user = message.mentions.users.first();
    // If we have a user mentioned
    if (user) {
      // Now we get the member from the user
      const member = message.guild.members.resolve(user);
      // If the member is in the guild

      const banemped = new Discord.MessageEmbed()
      .setColor('BLUE')
      .setTitle('Banned ')
      .setDescription(`Banned ${user.tag} `)
      .setTimestamp()

      if (member) {
        /**
         * Ban the member
         * Make sure you run this on a member, not a user!
         * There are big differences between a user and a member
         * Read more about what ban options there are over at
         * https://discord.js.org/#/docs/main/master/class/GuildMember?scrollTo=ban
         */
        member
          .ban({
            reason: 'They were bad!',
          })
          .then(() => {
            // We let the message author know we were able to ban the person
            message.channel.send(banemped);
          })
          .catch(err => {
            // An error happened
            // This is generally due to the bot not being able to ban the member,
            // either due to missing permissions or role hierarchy
            message.channel.send('I was unable to ban the member');
            // Log the error
            console.error(err);
          });
      } else {
        // The mentioned user isn't in this guild
        message.channel.send("That user isn't in this guild!");
      }
    } else {
      // Otherwise, if no user was mentioned
      message.channel.send("You didn't mention the user to ban!");
    }
    } else {
      message.channel.send('You dont have permission to ban ')
    }
    
  }




  if (message.content.startsWith('$kick')) {

   

    if (message.member.hasPermission("KICK_MEMBERS")) {
     // Assuming we mention someone in the message, this will return the user
    // Read more about mentions over at https://discord.js.org/#/docs/main/master/class/MessageMentions
    const user = message.mentions.users.first();
    // If we have a user mentioned
    if (user) {
      // Now we get the member from the user
      const member = message.guild.members.resolve(user);
      // If the member is in the guild

      const kickemped = new Discord.MessageEmbed()
      .setColor('BLUE')
      .setTitle('Kicked ')
      .setDescription(`Kicked ${user.tag} `)
      .setTimestamp()






      if (member) {
        /**
         * Ban the member
         * Make sure you run this on a member, not a user!
         * There are big differences between a user and a member
         * Read more about what ban options there are over at
         * https://discord.js.org/#/docs/main/master/class/GuildMember?scrollTo=ban
         */
        member
          .kick({
            reason: 'They were bad!',
          })
          .then(() => {
            // We let the message author know we were able to ban the person
            message.channel.send(kickemped);
          })
          .catch(err => {
            // An error happened
            // This is generally due to the bot not being able to ban the member,
            // either due to missing permissions or role hierarchy
            message.channel.send('I was unable to kick the member');
            // Log the error
            console.error(err);
          });
      } else {
        // The mentioned user isn't in this guild
        message.channel.send("That user isn't in this guild!");
      }
    } else {
      // Otherwise, if no user was mentioned
      message.channel.send("You didn't mention the user to kick!");
    }
    } else {
      message.channel.send('You dont have permission to kick')
    }
    
  }






  

});

// empeds here please
// inside a command, event listener, etc.
const help = new Discord.MessageEmbed()
    .setColor('#0099ff')
    .setTitle('Commands')
    .setURL('')
    .setAuthor('CaptainBeast', 'https://i.ibb.co/94KPj7q/ec46ca68e6b77bb5e8a085164b82fee8.png')
    .setDescription('Here are the list of some available commands')
    .setThumbnail('https://i.ibb.co/94KPj7q/ec46ca68e6b77bb5e8a085164b82fee8.png')
    .addFields(
        { name: 'Moderation', value: 'Moderation commands' },
        { name: '\u200B', value: '\u200B' },
        { name: '`$help`', value: 'Displays list of available commands', inline: true },
    { name: '`$ban @user`', value: 'Bans a member  ', inline: true },
    { name: '`$kick @user`', value: 'Kicks a member  ', inline: true },
    { name: '`$lock`', value: 'locks a channel', inline: true },
    { name: '`$unlock`', value: 'unlocks a channel', inline: true },
    { name: '`$mute @user <reason>`', value: 'mutes a user', inline: true },
    { name: '`$unmute @user <reason>`', value: 'unmutes a user', inline: true },
    { name: '`$clear <number>`', value: 'deletes messages [NOTE : 2 IS MIN AND 100 IS MAX]', inline: true },
    { name: '`$ping`', value: 'sent pong ', inline: true },

    { name: 'Fun', value: 'Fun commands' },
        { name: '\u200B', value: '\u200B' },

    { name: '`$meme`', value: 'sent meme', inline: true },
    { name: '`$cute`', value: 'sent cute stuffs', inline: true },
    { name: '`$joke`', value: 'sent sent jokes', inline: true },
    { name: '`$roast @user`', value: 'roast a user', inline: true },
    { name: '`$advice`', value: 'sent advices', inline: true },
    { name: '`$neko`', value: 'sent random neko images', inline: true },
    { name: '`$fact`', value: 'sent random facts', inline: true },
    { name: '`$animegif`', value: 'sent anime gif', inline: true },
    { name: '`$status <ip>`', value: 'fetchs status of a minecraft server', inline: true },



    )
    .setImage('')
    .setTimestamp()
    .setFooter('Made by CaptainBeast#1394', 'https://i.ibb.co/94KPj7q/ec46ca68e6b77bb5e8a085164b82fee8.png');
    
   
  const nuked = new Discord.MessageEmbed()

    .setColor('#34495E')
    .setTitle('Nuked')
    .setURL('')
    .setAuthor('CaptainBeast')
    .setDescription('Succesfully Nuked this channel')
    .setThumbnail('https://thumbs-prod.si-cdn.com/sIkNe_eIDylRJqhqZX7gk2KHtYc=/800x600/filters:no_upscale()/https://public-media.si-cdn.com/filer/dd/44/dd44ce31-4cc3-46c0-9378-0ec0da5a13e0/02_10_2014_romeo_nuke.jpg')
    .setFooter('Boom')
  
 


client.on("message", (message) => {
  // Exit and stop if it's not there
  if (!message.content.startsWith(prefix)) return;

  if (message.content.startsWith(prefix + "help")) {
    message.channel.send(help);
    
  } else
  if (message.content.startsWith(prefix + "foo")) {
    message.channel.send("bar!");
  }
  if (message.content.startsWith(prefix + "ping")) {
    message.channel.send("pong!");
  }
 
});




client.login(censored)

一个月前我也遇到了同样的问题,但我知道它第二天就开始工作了

标签: javascriptnode.jsdiscorddiscord.js

解决方案


您过于频繁地尝试更改机器人的状态,并且对于您的机器人所在的每个公会,这显然是一个问题。这是一个潜在的修复:

client.once('ready', () => {
    console.log('Beast Bot is ready');

    client.guilds.cache.forEach(guild => {
        console.log(`${guild.name} | ${guild.id}`);
    });

    setInterval(() => {
        let server = client.guilds.cache.reduce((a, b) => a + b.memberCount, 0)
        client.user.setPresence({
            activity: {
                name: `${server} members || $help ||.`,
                type: "WATCHING"
            },
            status: "online"
        });
    }, 5 * 60 * 1000); // updates the status every 5 minutes
});

推荐阅读