Hi how can I avoid reusing the same user?
I can’t find a solution to this. I have a list of 3 usernames but after he changes once he is unable to change to another one again.. Does anyone have a solution for this?
username_list = ['zRRrrwx2231221s', 'bzRRrrwx2231as', 'azRRrrwx2231s']
random_username = random.choice(username_list)
print('A randomly selected username is:', random_username)
with TelegramClient(StringSession(ses_string), api_id, api_hash) as client:
while True:
try:
time.sleep(10)
result = client(functions.channels.UpdateUsernameRequest(
channel= 'zRRrrwx2231221s' ,
username = random_username
))
telethon.errors.rpcerrorlist.UsernameNotModifiedError: The username is not different from the current username (caused by UpdateUsernameRequest)
I just want it to switch between the three users regularly – I don’t care if one of them catches I’ll switch.. but it can’t run thanks to the helpers
2
Answers
This
random_username = random.choice(username_list)
happens only once when you call it and is a variable. To make it possible to call it again you need a function like:Now instead of
username = random_username
you need to callusername = rnd_username()
As I mentioned in comments, it’s always trying to pick the same username. But the error you’re getting appears to be if you "change" the username, but it’s the same as before.
https://tl.telethon.dev/methods/account/update_username.html
If that’s the case, you have two options.
1: remember the username and just skip the change, so you don’t get the error. This has the added benefit of not attempting an api call that you know will fail.
2: just do it anyway, catch the exception, and then ignore it. Easier to ask forgiveness than permission programming. So add a handler for UsernameNotModifiedError.