Update: We suspect that the issue is related to my previous bot hosting service’s connection method to Discord. I’m switching to a different host to see if it resolves the problem.
I’ve never posed a question here before, but I need help! I created a straightforward bot that reads a file and sends a random line as a response. It functioned well until recently when Discord began shutting it down. I’m receiving the following error:
Your bot, x, has made over 1000 connections to Discord in a short duration. This behavior typically indicates a bug, so we have reset your bot’s token.
Here’s my current implementation. Any insights would be greatly appreciated!
// Import necessary libraries
const DiscordAPI = require('./node_modules/discord.js');
const botClient = new DiscordAPI.Client();
const settings = require('./settings.json');
const fileSystem = require('fs');
botClient.on('ready', () => {
console.log(`Bot is now active, serving ${botClient.guilds.size} servers`);
botClient.user.setActivity(`awaiting commands`);
});
botClient.on('guildCreate', (newGuild) => {
console.log(`Joined a new guild: ${newGuild.name}, which has ${newGuild.memberCount} members!`);
});
botClient.on('guildDelete', (removedGuild) => {
console.log(`Removed from guild: ${removedGuild.name}.`);
});
botClient.on('message', async (msg) => {
if (!msg.content.startsWith(settings.prefix) || msg.author.bot) return;
// Read jokes from the text file
fileSystem.readFile('jokes.txt', (error, content) => {
if (error) throw error;
const lines = content.toString().split('\n');
const randomIndex = Math.floor(Math.random() * lines.length);
msg.channel.send(lines[randomIndex]);
});
});
botClient.login(settings.token);
The last error log recorded is as follows:
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)