-
-
Notifications
You must be signed in to change notification settings - Fork 488
Description
Describe the Bug
I was upgrading the codebase of a Discord bot that used Asyncpraw for a long while to obtain posts, however I've begun to notice that the code that I had originally and the new code now have begun to break recently where, at certain times, the submission stream just begins to fetch old posts as if they were "new" causing the bot to post those old posts as if they were newly posted.
It seems the logic in skip_existing no longer works as of late? I tried searching in the r/redditdev subreddit and only a deleted post seems to refer to this issue.
Desired Result
SubmissionStream should only be fetching posts that are newly posted on a given subreddit.
Code to reproduce the bug
class Reddit(commands.Cog):
def __init__(self, bot):
self.bot: commands.Bot = bot # Discord.py
self.reddit_session: asyncpraw.Reddit
self.reddit_channel: TextChannel # Discord.py
async def fetch_subreddit_posts(self):
subreddit = await self.reddit_session.subreddit("arandomsubreddit")
logger.info("Fetching new subreddit posts...")
try:
async for submission in subreddit.stream.submissions(
skip_existing=True
):
embed_type = "link"
url_lower = submission.url.lower()
if url_lower.endswith((".jpg", ".jpeg", ".png", ".webp")):
embed_type = "image"
elif url_lower.endswith(".gif"):
embed_type = "gifv"
elif "youtu" in url_lower or "vimeo" in url_lower:
embed_type = "video"
elif submission.is_self:
embed_type = "rich"
if "reddit.com/gallery" in url_lower:
embed_type = "link" # Special handling for galleries
embed = create_submission_embed(submission, embed_type)
await self.reddit_channel.send(embed=embed)
except (ServerError, RequestException, Forbidden) as e:
logger.error(f"Error fetching subreddit posts: {e}")
except Exception as e:
logger.exception(f"Unexpected error: {e}")My code does not include sensitive credentials
- Yes, I have removed sensitive credentials from my code.
Relevant Logs
There isn't an error in the log file to comment here.This code has previously worked as intended
Yes
Operating System/Environment
Debian 13
Python Version
3.11.2
Async PRAW Version
7.8.1
Links, references, and/or additional comments?
https://www.reddit.com/r/redditdev/comments/1nzssc3/old_submissions_sporadically_showing_up_as_new/
https://www.reddit.com/r/redditdev/comments/1nrpyum/bot_responding_to_old_posts/