Tweepy bot to tweet DMs

You can get the DM messages with

auth = tweepy.OAuthHandler('api_key', 'api_secret')
auth.set_access_token('access_token', 'token_secret')

api = tweepy.API(auth)
messages = get_api().list_direct_messages(count=5)

The code above would rin in a thread to fetch the messages every x minutes.
Once you have the messages you can process the list, send the tweet and delete the DMs (to avoid processing it again).

for message in messages:
  text = message.message_create["message_data"]["text"]
  api.update_status(f'Tweet DM content: {text}'
  # remove DM

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top