I'm getting this error with my discord bot... This is my code:
const { createWorker } = require('tesseract.js');
const { Client, GatewayIntentBits } = require('discord.js');
const client = new Client({
intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent]
});
// Create and configure a worker instance
const worker = createWorker();
client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}`);
});
client.on('messageCreate', async (message) => { // Add async here
if (message.author.bot) return;
console.log(`Received a message from ${message.author.username}: ${message.content}`);
if (message.attachments.size > 0 && message.attachments.first().url) {
const imageUrl = message.attachments.first().url;
console.log(`Received an image from ${message.author.username}: ${imageUrl}`);
// Process the image with Tesseract OCR
try {
await worker.load();
await worker.loadLanguage('es'); // Replace 'eng' with the appropriate language code
await worker.initialize('es');
const { data: { text } } = await worker.recognize(imageUrl);
console.log('Extracted text:', text);
await worker.terminate();
// Send the extracted text as a message in the same channel
message.channel.send(`Extracted text: ${text}`);
} catch (error) {
console.error('Error occurred during OCR:', error);
message.channel.send(`Sorry, something went wrong. Please try again later.`);
}
}
});