【发布时间】:2021-07-09 18:08:30
【问题描述】:
更新:原来问题(我和一个朋友认为)是我的(现在以前的)机器人主机连接到 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