How I created a Reddit bot with Laravel

The boring part: research

  • Some subs had dedicated “flairs” for in-game pictures
  • Others didn’t, but a lot of the submission titles contained the word “screenshot
  • Creating a Reddit application
  • Authenticating via OAuth2 with the credentials provided by the application
  • Use the corresponding API calls to fetch the data I need

The fun part: programming and putting it all together

Figuring out the API calls

  1. Search subreddits that have a dedicated flair:
https://oauth.reddit.com/r/[SUBREDDIT]/search.json?q=flair:”[FLAIR]”&restrict_sr=1&sort=new
https://oauth.reddit.com/r/[SUBREDDIT]/search.json?q=title:[QUERY]&restrict_sr=1&sort=new
https://oauth.reddit.com/r/[SUBREDDIT]/new.json
https://oauth.reddit.com/api/submit
https://oauth.reddit.com/api/editusertext

Creating a client with Guzzle

Keeping track of cross-posts

php artisan make:model RedditCrossPost
Database snippet

A structured way to define the subreddits to scan

  • FlairQuery
  • SearchQuery
  • NewestQuery

Start cross-posting

$schedule->command('reddit:run-bot')->cron('*/15 * * * *')
* * * * * cd /path-to-your-project && php artisan schedule:run >> /dev/null 2>&1

Wrapping up

--

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

OceanDAO Round 14 is Live

Tips and Tricks for Debugging in the Frappe Framework

Introducing Balancer Simulations

How to use AWS Amplify and Angular to Build Cloud Enabled JavaScript Applications

BEST!! How To Bulk Rename Files In Windows 10 & 11

BEST!! How To Bulk Rename Files In Windows 10 & 11

Putting It Together — Converting Currencies 1

List of Top 5 Python Framework for App Development

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Robin Ingelbrecht

Robin Ingelbrecht

More from Medium

Factory Changes in Laravel 8

Define a Route Group Controller in Laravel 8.80

Email verification login using Laravel

LARAVEL 8 Features