Hi!
Im trying to create a discord bot that read images, but Im getting this
error:
Error occurred during OCR: TypeError: worker.load is not a function
at Client.<anonymous> (/srv/inkietud/index.js:29:26)
at Client.emit (node:events:513:28)
at MessageCreateAction.handle
(/srv/inkietud/node_modules/discord.js/src/client/actions/MessageCreate.js:28:14)
at module.exports [as MESSAGE_CREATE]
(/srv/inkietud/node_modules/discord.js/src/client/websocket/handlers/MESSAGE_CREATE.js:4:32)
at WebSocketManager.handlePacket
(/srv/inkietud/node_modules/discord.js/src/client/websocket/WebSocketManager.js:354:31)
at WebSocketManager.<anonymous>
(/srv/inkietud/node_modules/discord.js/src/client/websocket/WebSocketManager.js:238:12)
at WebSocketManager.emit
(/srv/inkietud/node_modules/@vladfrangu/async_event_emitter/dist/index.js:282:31)
at WebSocketShard.<anonymous>
(/srv/inkietud/node_modules/@discordjs/ws/dist/index.js:1103:51)
at WebSocketShard.emit
(/srv/inkietud/node_modules/@vladfrangu/async_event_emitter/dist/index.js:282:31)
at WebSocketShard.onMessage
(/srv/inkietud/node_modules/@discordjs/ws/dist/index.js:938:14)
This is my part of the code
client.on('messageCreate', async (message) => {
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.`);
}
}
});
--
You received this message because you are subscribed to the Google Groups
"tesseract-ocr" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/tesseract-ocr/38d9634c-3324-4094-a34a-9393fa3e4c2fn%40googlegroups.com.