├── requirements.txt ├── README.md └── script.py /requirements.txt: -------------------------------------------------------------------------------- 1 | TikTokLive 2 | pynput 3 | tomlkit -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # TikTokLive-Gift Bot 2 | This is a Python script that simulates a keypress or runs a function based on the gift received during a TikTok Live broadcast. 3 | 4 | # Installation 5 | To use this script, you'll need to clone this repository to your local machine using the following command: 6 | 7 | ```git clone https://github.com/Benioriginal/TikTokLive-Gift.git``` 8 | 9 | ### You'll also need to install the following dependencies using either of the following methods: 10 | 11 | **Method 1: Install the dependencies using pip:** 12 | 13 | ```pip install -r requirements.txt``` 14 | **Method 2: Install the dependencies manually:** 15 | 16 | **Python 3** 17 | **pynput library (can be installed via pip: pip install pynput)** 18 | 19 | # Usage 20 | Launch the script by running python script.py in your terminal. 21 | Enter the broadcast ID when prompted. 22 | Sit back and watch the bot automatically respond to gifts during the broadcast. 23 | 24 | # Configuration 25 | You can customize the bot's behavior by editing the gift_dict dictionary in gift_bot.py. This dictionary maps gift IDs to the function or keypress that should be simulated when that gift is received. 26 | 27 | # Contributing 28 | Contributions are welcome! If you find a bug or have an idea for a new feature, feel free to submit an issue or a pull request. -------------------------------------------------------------------------------- /script.py: -------------------------------------------------------------------------------- 1 | from TikTokLive import TikTokLiveClient 2 | from TikTokLive.types.events import CommentEvent, ConnectEvent 3 | import pynput 4 | from pynput.keyboard import Key, Controller 5 | from tomlkit import key 6 | keyboard = Controller() 7 | print(""" 8 | ░██████╗██╗░░░██╗██████╗░░██████╗░█████╗░██████╗░██╗██████╗░███████╗  ████████╗░█████╗░ 9 | ██╔════╝██║░░░██║██╔══██╗██╔════╝██╔══██╗██╔══██╗██║██╔══██╗██╔════╝  ╚══██╔══╝██╔══██╗ 10 | ╚█████╗░██║░░░██║██████╦╝╚█████╗░██║░░╚═╝██████╔╝██║██████╦╝█████╗░░  ░░░██║░░░██║░░██║ 11 | ░╚═══██╗██║░░░██║██╔══██╗░╚═══██╗██║░░██╗██╔══██╗██║██╔══██╗██╔══╝░░  ░░░██║░░░██║░░██║ 12 | ██████╔╝╚██████╔╝██████╦╝██████╔╝╚█████╔╝██║░░██║██║██████╦╝███████╗  ░░░██║░░░╚█████╔╝ 13 | ╚═════╝░░╚═════╝░╚═════╝░╚═════╝░░╚════╝░╚═╝░░╚═╝╚═╝╚═════╝░╚══════╝  ░░░╚═╝░░░░╚════╝░ 14 | 15 | ██████╗░░█████╗░██╗███╗░░██╗██████╗░░█████╗░███╗░░██╗  16 | ██╔══██╗██╔══██╗██║████╗░██║██╔══██╗██╔══██╗████╗░██║  17 | ██████╦╝███████║██║██╔██╗██║██████╦╝███████║██╔██╗██║  18 | ██╔══██╗██╔══██║██║██║╚████║██╔══██╗██╔══██║██║╚████║  19 | ██████╦╝██║░░██║██║██║░╚███║██████╦╝██║░░██║██║░╚███║  20 | ╚═════╝░╚═╝░░╚═╝╚═╝╚═╝░░╚══╝╚═════╝░╚═╝░░╚═╝╚═╝░░╚══╝  21 | """) 22 | name = input("tiktok id: ") 23 | 24 | # Instantiate the client with the user's username 25 | client: TikTokLiveClient = TikTokLiveClient(unique_id=f"@{name}") 26 | 27 | 28 | # Define how you want to handle specific events via decorator 29 | 30 | 31 | @client.on("connect") 32 | async def on_connect(_: ConnectEvent): 33 | print("Connected to Room ID:", client.room_id) 34 | 35 | 36 | # Notice no decorator? 37 | async def on_comment(event: CommentEvent): 38 | total_donations = 0 39 | total_donations += 1 40 | 41 | # Define handling an event via "callback" 42 | client.add_listener("comment", on_comment) 43 | 44 | 45 | @client.on("gift") 46 | async def on_gift(event): 47 | # If it's type 1 and the streak is over 48 | if event.gift.gift_type == 1: 49 | if event.gift.repeat_end == 1: 50 | print( 51 | f"{event.user.uniqueId} sent {event.gift.repeat_count}x \"{event.gift.extended_gift.name}\"") 52 | keyboard.press(Key.up) 53 | keyboard.release(Key.up) 54 | # It's not type 1, which means it can't have a streak & is automatically over 55 | elif event.gift.gift_type != 1: 56 | print(f"{event.user.uniqueId} sent \"{event.gift.extended_gift.name}\"") 57 | keyboard.press(Key.up) 58 | keyboard.release(Key.up) 59 | if __name__ == '__main__': 60 | # Run the client and block the main thread 61 | # await client.start() to run non-blocking 62 | client.run() 63 | --------------------------------------------------------------------------------