Search code examples
pythondiscord.pytweepy

Discord.py @client.event twitter automatically post into specific channel


So i have a discord bot where its used to post a stuff from twitter timeline using tweepy, the auto post seems ok but its sending the old timeline also everytime the bot is turned on. Im still confused on how to make the bot only send new tweet from twitter timeline. Heres the code i have :

timeline = api.home_timeline()

@client.event
async def on_message(message):
    for tweet in timeline:
        channel = client.get_channel(CHANNELID)
        em1 = discord.Embed(title = f'New Tweet From {tweet.user.name}.', description = f'{tweet.text}.')
        await channel.send(embed = em1)

Solution

  • Store the ids of tweets you've already sent in a database of some sorts, and use that to filter out the ones that you haven't sent yet. Also I'm a bit confused why you'd do this in on_message? That doesn't make a whole lot of sense to me.