I'm trying to read a .txt file (currently empty) to check if chat_id already exists, if it already exists, it ends there. If it does not exist ... Add the new chat_id in the last line, but when I run the code and see the file, there is nothing written on it and it does not show any error in the terminal ... Where am I going wrong?
def add_chat(self):
#print(self.msg_chat_id) output: -10052348214
with open('bot_chat_ids.txt', 'r') as allchats:
for chat in allchats:
if str(self.msg_chat_id) == chat:
return
with open('bot_chat_ids.txt', 'a') as allchats:
allchats.write(str(self.msg_chat_id) + '\n')