String Session

You'll need a Pyrogram v2 String Session for the Music bot

You'll need a API_ID and API_HASH in order to generate pyrogram session. Always remember to use good API combo else your account could be deleted.

How to get API_ID and API_HASH ?

  • Go to my.telegram.org then Enter your Phone Number with your country code.

  • After, you are logged in click on API Development Tools.

  • Enter Anything as App name and App short name, Enter my.telegram.org in url section

  • That’s it, You”ll get your API_ID ans API_HASH.

Generate Session through local/VPS

Method 1

Simply run this code and give the input which is being asked and you will get String Session

#!/bin/bash

# Check if pyrogram is installed and the version is >= 2.0.106
python -c "try:\n    import pyrogram\n    if hasattr(pyrogram, '__version__') and tuple(map(int, pyrogram.__version__.split('.'))) >= (2, 0, 106):\n        print('Pyrogram version is sufficient.')\n        exit(0)\n    else:\n        print('Pyrogram version is older than 2.0.106.')\n        exit(1)\nexcept ImportError:\n    print('Pyrogram is not installed.')\n    exit(1)"

# Install pyrogram if not installed or version is older
echo "Installing pyrogram (version >= 2.0.106)..."
pip install pyrogram>=2.0.106

echo "\n=== Telegram API Credentials ==="
read -p "Enter Your API_ID: " api_id
read -p "Enter Your API_HASH: " api_hash

echo "\nEnter Phone number when asked.\n"

session_name=":memory:"

python -c "
import asyncio
import os
from pyrogram import Client as c

async def main():
    api_id = '$api_id'
    api_hash = '$api_hash'
    session_name = '$session_name'
    i = c(session_name, api_id=api_id, api_hash=api_hash)

    try:
        await i.start()
        ss = await i.export_session_string()
        xx = f'HERE IS YOUR STRING SESSION, COPY IT, DON\\'T SHARE!!\\n\\n`{ss}`\\n\\nGENERATED BY Stranger'
        await i.send_message('me', xx)
        print('\\nHERE IS YOUR STRING SESSION, COPY IT, DON\\'T SHARE!!\\n')
        print(f'\\n{ss}\\n')
        print('\\nGENERATED BY Stranger\\n')
    finally:
        session_file = f'{session_name}.session'
        if os.path.exists(session_file):
            os.remove(session_file)

if __name__ == '__main__':
    asyncio.run(main())
"

How to Run:

  1. Save the code above in a file named start.sh (or any other name with a .sh extension).

  2. Make the script executable: chmod +x start.sh

  3. Run the script: ./start.sh

Method 2

Clone the Stranger repo and run the gensession file

git clone https://github.com/xbitcode/StrangerMusicBot \
&& cd StrangerMusicBot
bash gensession

Enter the details for getting the string session

  • API_ID

  • API_HASH

  • and enter the phone number when asked

Clean the files

cd .. \
&& sudo rm -r StrangerMusicBot

Last updated