i am working on a telethon script of python which runs if the channel/group receives new message i am looking at the message id for running my script i am a beginner of python so with what knowledge i have
i am using this following code.
prev_msgid=0
latest_msgid = message.id
if latest_msgid>prev_msgid:
print('latest message')
prev_msgid = message.id
else:
print('old message')
but when i run this code every time the previous message resets to 0
i need a way for when i run this code multiple times the prev_msgid
is automatically changed to the latest message id.
thank you.
like @Quba said you need a way to store data in persistent way
Pickle is the fastest solution for you. It can save python object as a file:
Every time you run the script it will add one to prev_msgid. See that it makes a file that named "prev_msgid"