I'm working on a custom bot to send a message in a Discord channel every time a new post is made on a subreddit. With this, it just sends a link to the same post every 30 seconds, the post never changes to the most recent one. I need help figuring out how to check if a post has already been posted, as well as how to post the most recent post on the subreddit.
import discordimport osimport feedparserfrom discord.ext import tasks, commandsgot_token = os.environ['TOKEN']client = discord.Client(intents=discord.Intents.default())bot = commands.Bot(command_prefix='$', intents=discord.Intents.default())@client.event@bot.listen()async def on_ready(): print('We have logged in as {0.user}'.format(client)) task_loop.start()@tasks.loop(seconds=30)async def task_loop(): Feed = feedparser.parse('https://www.reddit.com/r/askreddit/.rss') entry = Feed.entries[1] channel = client.get_channel(351023004001763339) await channel.send(entry.link)client.run(got_token)
So I tried to fix it by
I tried to store the title as a string and compare to see if the title was the last one posted. The only problem is I can't initialize any variables outside
async def task_loop():
loop. This is also why I can't change the array to be i and then increment i. The start of the loop just changes the value of i or the string back to the starting value every time.