A code that change the group link every 5 mins not the invite link only the original group link to fragment links and I need you to be able to make the bot in the group will change the link not the owner of the group
` import logging
import time
from telethon import TelegramClient
from telethon.errors import UsernameOccupiedError
# Set up logging
logging.basicConfig(
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
level=logging.INFO
)
logger = logging.getLogger(__name__)
# Define your API ID, API Hash, bot token, and group username details
API_ID = 'YOUR_API_ID'
API_HASH = 'YOUR_API_HASH'
PHONE_NUMBER = 'YOUR_PHONE_NUMBER' # The phone number associated with your account
GROUP_USERNAME = 'initial_group_link'
NEW_GROUP_USERNAMES = ['new_link_1', 'new_link_2', 'new_link_3']
# Initialize the Telegram client
client = TelegramClient('session_name', API_ID, API_HASH)
async def change_group_link(new_username):
try:
await client.connect()
if not await client.is_user_authorized():
await client.send_code_request(PHONE_NUMBER)
await client.sign_in(PHONE_NUMBER, input('Enter the code: '))
# Attempt to update the group's username
try:
await client(functions.channels.UpdateUsernameRequest(
channel=GROUP_USERNAME,
username=new_username
))
logger.info(f"Changed group username to: {new_username}")
except UsernameOccupiedError:
logger.error(f"Username {new_username} is already taken.")
except Exception as e:
logger.error(f"Failed to change group username: {e}")
finally:
await client.disconnect()
def main():
for new_username in NEW_GROUP_USERNAMES:
client.loop.run_until_complete(change_group_link(new_username))
time.sleep(300) # Wait for 5 minutes before changing again
if __name__ == '__main__':
main()`
I did it but why is it not working?
New contributor
mark alex is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.