首页 > 解决方案 > Discord 机器人在 24 小时内连接 1000 次

问题描述

更新:原来问题(我和一个朋友认为)是我的(现在以前的)机器人主机连接到 Discord 的方式。所以我正在尝试一个新的主机,看看它是否有帮助......

这是我第一次不得不崩溃并提出问题......我有一个简单的机器人,它读取文件并从中返回随机行。直到最近它开始被 Discord 关闭时,它一直运行良好。我收到此错误:

您的机器人 x 似乎在短时间内连接到 Discord 超过 1000 次。由于这种行为通常是错误的结果,我们已经继续并重置了您的机器人的令牌。

这是我的代码。谢谢你提供的所有帮助。

// Require stuff, declare stuff
const Discord = require("./node_modules/discord.js");
const client = new Discord.Client();
const config = require("./config.json");
var http = require('http');
const fs = require('fs');
var err = '';
var data = '';

// This section lifted from https://gist.github.com/eslachance

client.on("ready", () => {
    // This event will run if the bot starts, and logs in, successfully.
    console.log(`Bot has started, serving ${client.guilds.size} servers`);
    client.user.setActivity(`command`);
}, (err, data));

client.on("guildCreate", guild => {
    // This event triggers when the bot joins a guild.
    console.log(`New guild joined: ${guild.name} . This guild has ${guild.memberCount} members!`);
    client.user.setActivity(`command`);
}, (err, data));

client.on("guildDelete", guild => {
    // this event triggers when the bot is removed from a guild.
    console.log(`I have been removed from: ${guild.name} .`);
    client.user.setActivity(`command`);
}, (err, data));


client.on("message", async message => {

    try {
 
        // This event will run on every single message received, from any channel or DM.

        if (!msg.content.startsWith(config.prefix) || msg.author.bot) return;

        // And now, my part!

        // Read in the file of cat jokes and make it an array
        fs.readFile('textfile.txt', function(err, data) {
            if(err) throw err;
            const content = data.toString();
            const allLines = content.split("\n");
            var linenum = Math.floor(Math.random() * allLines.length);
                
            // Reply to the command with the random joke
            message.channel.send(allLines[linenum]);      

        });

    } catch(e) {
        console.log('Error caught');
    }

}, (err, data));

client.login(config.token);

日志中最近的错误是:

TypeError: Cannot read property 'id' of undefined
    at ClientDataManager.newChannel (/root/chester/node_modules/discord.js/src/client/ClientDataManager.js:81:36)
    at Guild.setup (/root/chester/node_modules/discord.js/src/structures/Guild.js:307:68)
    at GuildCreateHandler.handle (/root/chester/node_modules/discord.js/src/client/websocket/packets/handlers/GuildCreate.js:12:15)
    at WebSocketPacketManager.handle (/root/chester/node_modules/discord.js/src/client/websocket/packets/WebSocketPacketManager.js:108:65)
    at WebSocketConnection.onPacket (/root/chester/node_modules/discord.js/src/client/websocket/WebSocketConnection.js:336:35)
    at WebSocketConnection.onMessage (/root/chester/node_modules/discord.js/src/client/websocket/WebSocketConnection.js:299:17)
    at WebSocket.onMessage (/root/chester/node_modules/ws/lib/event-target.js:120:16)
    at WebSocket.emit (events.js:315:20)
    at Receiver.receiverOnMessage (/root/chester/node_modules/ws/lib/websocket.js:789:20)
    at Receiver.emit (events.js:315:20)

标签: discord.js

解决方案


此错误表示您在 24 小时内“登录”机器人的次数过多。当您在 24 小时内运行机器人 1000 次时,就会发生这种情况。要修复此错误,请转到 discord 开发人员门户,重新生成您的机器人令牌,然后将新令牌粘贴到您的代码中。


推荐阅读