Skip to content

Instantly share code, notes, and snippets.

@kyriog
Last active October 16, 2022 15:41
Show Gist options
  • Save kyriog/54f81ef59f5d4139aa2f to your computer and use it in GitHub Desktop.
Save kyriog/54f81ef59f5d4139aa2f to your computer and use it in GitHub Desktop.
Post Tweets from an account to Discord channel
#!/usr/bin/env python
# -*- coding: utf8 -*-
import discord, tweepy, time
TWITTER_CONSUMER_KEY = u''
TWITTER_CONSUMER_SECRET = u''
TWITTER_ACCESS_TOKEN = u''
TWITTER_TOKEN_SECRET = u''
TWITTER_FOLLOWED_ACCOUNT = u''
DISCORD_EMAIL = u''
DISCORD_PASSWORD = u''
DISCORD_CHANNEL = u''
class EcoTwitterListener(tweepy.StreamListener):
def on_status(self, status):
if status.in_reply_to_status_id is not None:
message = u'Nouvelle réponse à @{} : {}'.format(status.in_reply_to_screen_name, status.text)
else:
message = u'Nouveau tweet : {}'.format(status.text)
client.send_message(channel, message.encode('utf8'))
client = discord.Client()
client.login(DISCORD_EMAIL, DISCORD_PASSWORD)
if not client.is_logged_in:
raise Exception(u'Unable to connect to Discord')
i = 0
channel = None
while channel is None:
i += 1
print u'Attempt {} to get Discord channel'.format(i)
channel = client.get_channel(DISCORD_CHANNEL)
time.sleep(1)
print u'Retrieved #{} channel on {} server'.format(channel.name, channel.server.name)
auth = tweepy.OAuthHandler(TWITTER_CONSUMER_KEY, TWITTER_CONSUMER_SECRET, callback=u'oob')
auth.secure = True
auth.set_access_token(TWITTER_ACCESS_TOKEN, TWITTER_TOKEN_SECRET)
print u'Starting Twitter Stream'
ecoStream = tweepy.Stream(auth=auth, listener=EcoTwitterListener())
ecoStream.filter(follow=[TWITTER_FOLLOWED_ACCOUNT])
@radzuky
Copy link

radzuky commented Oct 1, 2016

I know this is old, but how do you run this. Looks interesting.

@yourmomkindacute
Copy link

hey bro sorry for the late response but u just do it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment