Closed CryptosWizard closed 3 years ago
I think you're misusing javascript. the correct way to pass args with names is as follows.
new NewMessage({chats: [1,2,3]}
but it's better to filter the chat ids inside the event than to use in the args because the library needs to have seen it first and that's not possible with using string session. so change the event to something like
async function eventPrint(event) {
console.log("Enter evenPrint")
if ([-10014564654,-1005468654].includes(event.chatId)){
return;
}
}
chatId would return bot API style ids so make sure to use -100 if it's a channel/supergorup
I think you're misusing javascript. the correct way to pass args with names is as follows. new NewMessage({chats: [1,2,3]}
Yeah i tried that, then i got desperated and tried strange way of doing it just in case.
client.addEventHandler(eventPrint, new events.NewMessage({chats : [1111111, -2222222]})
is not working with same error and you said to put nothing inside i wanted to do that but when i doclient.addEventHandler(eventPrint, new events.NewMessage({})
same error and client.addEventHandler(eventPrint, new NewMessage({})
say NewMessage is not defined so i imported events and put it in front as in the #74
it doesn't matter how you import it as long as you import it.
That doesn't change the fact that
client.addEventHandler(eventPrint, new events.NewMessage({})
client.addEventHandler(eventPrint, new events.NewMessage({chats : [1111111, -2222222]})
are both sending
(node:35192) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'NewMessage' of undefined
at init (*******************\js-botbsc-348\telegram_read.js:64:51)
at processTicksAndRejections (internal/process/task_queues.js:93:5)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:35192) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:35192) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
well that's really more like a javascript/typescript issue.
make sure to import it correctly
const { NewMessage } = require('telegram/events')
or
import { NewMessage } from "telegram/events"
Ok indeed that was an import problem
const { events } = require('telegram')
is not enough to use events.NewMessage
my bad
Thank you for taking the time !
Hello, I tried to make the EventHandler works for new message but didn't succeed.
Here is my code, i just do some basic send and loading before the handler to be sure the connection is working.
I checked https://painor.gitbook.io/gramjs/getting-started/updates-events , https://github.com/gram-js/gramjs/issues/74 and https://github.com/gram-js/gramjs/pull/12 to understand how NewMessage works, i'm using Telethon also so the lib is not too foreign but can t make that Handler works.
If i put client.addEventHandler(eventPrint); the code is working fine but got too much event to filter. }
The message is send then i load the 10 messages and then i got the Error :