A Twitter bot written in Python. The recurrent neural network Twitter bot tweets generated text with a temperature of 0.7 from the trained model.
Starting February 9, we will no longer support free access to the Twitter API, both v2 and v1.1. A paid basic tier will be available instead π§΅
β Twitter Dev (@TwitterDev) February 2, 2023
- Getting Started
- Instructions
- Contributing
- Creator / Maintainer
- Acknowledgments
- Additional Information
Make sure to follow Twitter's Automation Rules to avoid getting your account banned.
- textgenrnn Colaboratory Notebook - easily train your own text-generating neural network of any size and complexity for free on a GPU using Colaboratory
- Python 3.6 or 3.7
- Pip - a python package manager
- Download this file, open a command prompt and navigate to the folder containing the
get-pip.pyinstaller, and runpython get-pip.pyto install- Run
pip --versionto check if it has installed correctly
- Run
- Download this file, open a command prompt and navigate to the folder containing the
- Tweepy - an easy-to-use python library for accessing Twitter's API
- Run
pip install tweepy
- Run
- textgenrnn - a python3 module to easily train your own text-generating neural network of any size and complexity on any text dataset with a few lines of code, or quickly train on a text using a pretrained model
- Run
pip install textgenrnn
- Run
-
Apply for Twitter Developer Access with the account you want the bot to be used for.
-
Create a new Twitter Application to generate your private keys, secrets, and tokens.
- Make sure the app settings has Read and Write permissions.
- Create a file named
credentials.pyto hold your private information using the format below.- See File Structure.
TWITTER_API_KEY="xxxx"
TWITTER_API_KEY_SECRET="xxxx"
TWITTER_ACCESS_TOKEN="xxxx"
TWITTER_ACCESS_TOKEN_SECRET="xxxx"
-
Adjustments you can make in
config.pyto tweak the bot to your liking. (Make sure to follow Twitter's Automation Rules to avoid getting your account banned.)- model_name - (MUST CHANGE) Name of the model used for the weights and configuration files you downloaded from Colaboratory.

- temperature - Level of randomness for the predicted text. Higher temperature will generate crazier text.
- prefix - Set a prefix if you want each generated text to start with a given seed text.
- n - Number of texts to generate.
- max_gen_length - Maximum number of characters for each text generated.
- max_tweet_length - Maximum number of characters for each tweet to have.
- If the generated text is too long, it will be split into multiple tweets at this length.
- Set to 280 (Twitter's character limit for tweets) if you are not adding anything to the end of the tweets.
- add_to_tweet - Optional if you want to add text to end of every tweet.
- Set to None if you do not want to use.
- delay - Time to wait in between each tweet in seconds.
- min_tweet_length - Minimum number of characters in the tweet, will ignore tweets that are not long enough.
- Set to 0 if this is not relevant to you.
- model_name - (MUST CHANGE) Name of the model used for the weights and configuration files you downloaded from Colaboratory.
-
Use the textgenrnn Colaboratory Notebook to train your RNN.
- See Additional Information for more details.
-
Download the weights and configuration files from the Colaboratory Notebook (as shown below) and put them in the
modeldirectory- See File Structure.
- Install all required packages needed to run the script
pip install -r requirements.txt
- Run the script. Enjoy your Twitter bot!
python twitter-ai-bot.py
RNN-Twitter-Bot
|-- model
| |-- yourmodelname_config.json
| |-- yourmodelname_vocab.json
| `-- yourmodelname_weights.hdf5
|-- credentials.py
`-- twitter-ai-bot.py
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change. Please make sure to update tests as appropriate.
- Fork the repository to your own Github account.
- Clone the project to your machine.
- Create a branch locally with a succinct but descriptive name.
- Commit changes to the branch.
- Following any formatting and testing guidelines specific to this repo.
- Push changes to your fork.
- Open a Pull Request in my repository.
Annie Wu (anniedotexe)
Copyright Β© 2021-2026 Annie Wu. All rights reserved.
I do not maintain this code anymore and will not respond to any questions sent to me.
If you like my content or find this code useful, give it a β or support me by buying me a coffee βπ
- Max Woolf
- creator of textgenrnn
- creator of the textgenrnn Colaboratory Notebook that allows us to quickly train the RNN with a GPU for free



