From ffa5aaa8bab077ee3236818f1a72f432e7de1560 Mon Sep 17 00:00:00 2001 From: Marco Thomas Date: Fri, 9 Oct 2020 12:33:35 +0200 Subject: [PATCH] Show message when subreddit invalid --- cogs/reddit.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/cogs/reddit.py b/cogs/reddit.py index 0742532..fed706d 100644 --- a/cogs/reddit.py +++ b/cogs/reddit.py @@ -26,6 +26,11 @@ class Reddit(commands.Cog): client_secret=REDDIT_CLIENT_SECRET, user_agent=REDDIT_CLIENT_USERAGENT) + try: + reddit.subreddits.search_by_name(sub, exact=True) + except: + await ctx.send(f"Subreddit {sub} not found!") + try: if sorting == "hot": posts = reddit.subreddit(sub).hot() @@ -45,10 +50,10 @@ class Reddit(commands.Cog): if submission.over_18 and not ctx.channel.is_nsfw(): await ctx.send("The post is marked as NSFW, but your text channel isn't!") else: - text = f"" + text = "" if submission.over_18: text += "❗ NSFW ❗" - text += "'{submission.title}' by {submission.author.name} - 🔼 {submission.score}" + text += f"'{submission.title}' by {submission.author.name} - 🔼 {submission.score}" await ctx.send(text) await ctx.send(submission.url)