A Discord bot that fetches Reddit posts from subreddits and can run various custom commands for fun.
- Python Reddit API Wrapper - PRAW
- discord.py
- python-3.9.0
- Setup virtual environment and activate it
$ python -m venv venv
$ cd venv/Scripts
$ activate.bat
$ cd ..
$ cd ..
- Get Reddit Developer API constants
App Type: script
URL/URI: http://localhost:8080/
-
Setting up discord.py
- create application
- create a bot
- get OAuth link
- open the above link and add bot to a server
- copy api-key from bot page to code
-
Running bot locally
$ py bot.py
- Running on Heroku
- Create and populate:
Procfile
,runtime.txt
,requirements.txt
and place in root of the bot folder alongwithbot.py
$ pip freeze > requirements.txt
- Push to GitHub, create a new app in Heroku and attach to GitHub repository for CI (all via UI)
- Check build logs in
Deploy -> More -> View logs
- Goto
Resources
, specify run command aspy bot.py
and start a dyno. Check logs to make sure its running. Once the bot is ready to accept commands it will outputBot ready!
on Heroku log console.
- Fetch: a random post from specified subreddit, optional [hot] argument fetches a random but "hot" post (w/ NSFW Filter).
- Custom fun commands: toss a coin, show a gif on named commands.
- Other: memeLoop, stats system, responds with a custom message on @mention, activity status.
hello
help
stats
toss
meme [hot]
puppy
art [hot]
wallpaper [hot]
whoa [hot]
itemshop
comic [hot]
quote
showerthot [hot]
scary [hot]
other hardcoded named commands under `# secret commands`
- Uses embeds for better look and feel
- Custom Loggging: logs
await
success or failure in India Standard Time (GMT+5:30)pytz
- memeLoop: Sends a random hot meme to a specified channel every 30mins (w/ NSFW Filter)
random
- Stats System: TBI
OOP
- PRAW Basics with Flask Backend - Medium (behind signup wall? use Incognito)
- Code With Swastik - YouTube
- StackOverflow (ofcourse!)
- Deploying to Heroku - dev.to
Flask installation and app file app.py
is available to test PRAW. Better use Quart because of better async
functionality than Flask.
$ py app.py