Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import discord
- from discord.ext import commands
- from discord.utils import get
- import tweepy
- from tweepy import Stream
- from tweepy.streaming import StreamListener
- import datetime
- # Declare Discord intents
- intents = discord.Intents.default()
- intents.members = True
- # Create bot prefix for commands
- bot = commands.Bot(command_prefix='$', intents=intents)
- # Credentials
- DISCORD_TOKEN = xx
- TWITTER_CONSUMER_KEY = xx
- TWITTER_CONSUMER_SECRET = xx
- TWITTER_ACCESS_TOKEN = xx
- TWITTER_ACCESS_SECRET = xx
- # Authenticate to Twitter
- twitterAuth = tweepy.OAuthHandler(TWITTER_CONSUMER_KEY, TWITTER_CONSUMER_SECRET)
- twitterAuth.set_access_token(TWITTER_ACCESS_TOKEN, TWITTER_ACCESS_SECRET)
- twitterAPI = tweepy.API(twitterAuth, wait_on_rate_limit=True, wait_on_rate_limit_notify=True)
- # Create Twitter Listener
- class tweetListener(StreamListener):
- async def on_status(self, status):
- if status.in_reply_to_status_id is None:
- await on_tweet(status)
- async def on_tweet(status):
- channel = await bot.get_channel(843489980441427969)
- await channel.send("Fetching Tweet...")
- await channel.send(status.text)
- print(status.text)
- @bot.command(name="twitter")
- async def twitter(ctx):
- print('Got Twitter command')
- # Create embed
- embed = discord.Embed(title="@2NUProductions", url="https://twitter.com/2nuProductions", description="Follow us on Twitter!", color=discord.Color.green())
- embed.set_thumbnail(url="https://pbs.twimg.com/profile_images/1394411027970740224/QtJKEZaQ_400x400.jpg")
- await ctx.send(embed=embed)
- @bot.command(name="info")
- async def info(ctx):
- print('Info command received.')
- # Create embed
- embed = discord.Embed(title=f"{ctx.guild.name}", description="2NUproductions.com", timestamp=datetime.datetime.utcnow(), color=discord.Color.green())
- embed.add_field(name="Server Location", value=":flag_us: USA")
- embed.add_field(name="Total Members", value=f"{ctx.guild.member_count}")
- embed.set_thumbnail(url=f"{ctx.guild.icon_url}")
- # Send embed to channel
- await ctx.send(embed=embed)
- @bot.event
- async def on_ready():
- print('We have logged in as {0.user}'.format(bot))
- await bot.change_presence(activity=discord.Activity(type=discord.ActivityType.watching, name="2NUproductions.com"))
- try:
- twitterAPI.verify_credentials()
- print("Twitter authentication successful.")
- except:
- print("Error during authentication to Twitter.")
- newListener = tweetListener()
- newStream = tweepy.Stream(auth=twitterAPI.auth, listener=newListener)
- newStream.filter(follow=['1396846980303888395'], is_async=True)
- bot.run(DISCORD_TOKEN)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement