Advertisement
Guest User

Untitled

a guest
Jun 3rd, 2021
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.63 KB | None | 0 0
  1. import discord
  2. from discord.ext import commands
  3. from discord.utils import get
  4. import tweepy
  5. from tweepy import Stream
  6. from tweepy.streaming import StreamListener
  7. import datetime
  8.  
  9. # Declare Discord intents
  10. intents = discord.Intents.default()
  11. intents.members = True
  12.  
  13. # Create bot prefix for commands
  14. bot = commands.Bot(command_prefix='$', intents=intents)
  15.  
  16. # Credentials
  17. DISCORD_TOKEN = xx
  18. TWITTER_CONSUMER_KEY = xx
  19. TWITTER_CONSUMER_SECRET = xx
  20. TWITTER_ACCESS_TOKEN = xx
  21. TWITTER_ACCESS_SECRET = xx
  22.  
  23. # Authenticate to Twitter
  24. twitterAuth = tweepy.OAuthHandler(TWITTER_CONSUMER_KEY, TWITTER_CONSUMER_SECRET)
  25. twitterAuth.set_access_token(TWITTER_ACCESS_TOKEN, TWITTER_ACCESS_SECRET)
  26. twitterAPI = tweepy.API(twitterAuth, wait_on_rate_limit=True, wait_on_rate_limit_notify=True)
  27.  
  28. # Create Twitter Listener
  29. class tweetListener(StreamListener):
  30.     async def on_status(self, status):
  31.         if status.in_reply_to_status_id is None:
  32.             await on_tweet(status)
  33.  
  34. async def on_tweet(status):
  35.     channel = await bot.get_channel(843489980441427969)
  36.     await channel.send("Fetching Tweet...")
  37.     await channel.send(status.text)
  38.     print(status.text)
  39.  
  40.  
  41. @bot.command(name="twitter")
  42. async def twitter(ctx):
  43.     print('Got Twitter command')
  44.     # Create embed
  45.     embed = discord.Embed(title="@2NUProductions", url="https://twitter.com/2nuProductions", description="Follow us on Twitter!", color=discord.Color.green())
  46.     embed.set_thumbnail(url="https://pbs.twimg.com/profile_images/1394411027970740224/QtJKEZaQ_400x400.jpg")
  47.     await ctx.send(embed=embed)
  48.  
  49.  
  50. @bot.command(name="info")
  51. async def info(ctx):
  52.     print('Info command received.')
  53.     # Create embed
  54.     embed = discord.Embed(title=f"{ctx.guild.name}", description="2NUproductions.com", timestamp=datetime.datetime.utcnow(), color=discord.Color.green())
  55.     embed.add_field(name="Server Location", value=":flag_us: USA")
  56.     embed.add_field(name="Total Members", value=f"{ctx.guild.member_count}")
  57.     embed.set_thumbnail(url=f"{ctx.guild.icon_url}")
  58.     # Send embed to channel
  59.     await ctx.send(embed=embed)
  60.  
  61.  
  62. @bot.event
  63. async def on_ready():
  64.     print('We have logged in as {0.user}'.format(bot))
  65.     await bot.change_presence(activity=discord.Activity(type=discord.ActivityType.watching, name="2NUproductions.com"))
  66.  
  67. try:
  68.     twitterAPI.verify_credentials()
  69.     print("Twitter authentication successful.")
  70. except:
  71.     print("Error during authentication to Twitter.")
  72.  
  73. newListener = tweetListener()
  74. newStream = tweepy.Stream(auth=twitterAPI.auth, listener=newListener)
  75. newStream.filter(follow=['1396846980303888395'], is_async=True)
  76.  
  77. bot.run(DISCORD_TOKEN)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement