Answer the question
In order to leave comments, you need to log in
How to avoid duplicates when writing chat.id to a file?
There is a code:
global sub
sub = [line.rstrip('_\n') for line in open(subfile,'rt')]
if str(m.chat.id) not in sub:
with open(subfile, 'a') as f:
f.write(str(m.chat.id) + " \n")
else:
bot.send_message(m.chat.id, 'hi')
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question