Show message when subreddit invalid

This commit is contained in:
Marco Thomas
2020-10-09 12:33:35 +02:00
parent fdf38f2978
commit ffa5aaa8ba

View File

@@ -26,6 +26,11 @@ class Reddit(commands.Cog):
client_secret=REDDIT_CLIENT_SECRET, client_secret=REDDIT_CLIENT_SECRET,
user_agent=REDDIT_CLIENT_USERAGENT) user_agent=REDDIT_CLIENT_USERAGENT)
try:
reddit.subreddits.search_by_name(sub, exact=True)
except:
await ctx.send(f"Subreddit {sub} not found!")
try: try:
if sorting == "hot": if sorting == "hot":
posts = reddit.subreddit(sub).hot() posts = reddit.subreddit(sub).hot()
@@ -45,10 +50,10 @@ class Reddit(commands.Cog):
if submission.over_18 and not ctx.channel.is_nsfw(): 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!") await ctx.send("The post is marked as NSFW, but your text channel isn't!")
else: else:
text = f"" text = ""
if submission.over_18: if submission.over_18:
text += "❗ NSFW ❗" 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(text)
await ctx.send(submission.url) await ctx.send(submission.url)