def subreddit_new(self, ctx, subreddit: str, post_count: int=3):
"""Command for getting subreddit's new posts"""
if post_count <= 0 or post_count > 100:
await self.bot.say("Sorry, I can't do that")
else:
url = "https://oauth.reddit.com/r/{}/new".format(subreddit)
url += "?limit=" + str(post_count)
headers = {
"Authorization": "bearer " + self.access_token,
"User-Agent": "Red-DiscordBotRedditCog/0.1 by /u/palmtree5"
}
async with aiohttp.get(url, headers=headers) as req:
resp_json = await req.json()
if "data" not in resp_json and resp_json["error"] == 403:
await self.bot.say("Sorry, the currently authenticated account does not have access to that subreddit")
return
resp_json = resp_json["data"]["children"]
await self.post_menu(ctx, resp_json, page=0, timeout=30)
评论列表
文章目录