Using an AI Bot to Make a Reddit Bot
Summary
TLDRThe video outlines how to create a Reddit bot using Bing AI chat to automatically find and repost prompts from Reddit's r/midjourney subreddit. The goal is to help people access prompts to create their own AI generated images. The narrator starts by explaining why he prefers to use Bing chat over ChatGPT for coding - mainly the lack of need for a phone number and more capabilities. After asking Bing to generate Python code for a Reddit bot using the Python Reddit API Wrapper (PRAW), the narrator copies the code into an editor to make tweaks over multiple iterations. Key steps covered include getting Reddit API credentials for the bot, registering the bot as a Reddit user, adding code for authorized Reddit instance creation, searching specific criteria like posts with “imagine” and “prompt” keywords, cross-posting qualifying posts to a new subreddit, and commenting the matching prompt text. Several coding best practices are suggested such as: using Bing's Precise mode for writing code instead of Creative; adding print statements to debug code; using comments liberally; writing prompts in a separate doc before entering into Bing; and version controlling code on GitHub. The narrator also stresses the importance of collaborating with Bing during coding by asking clarifying questions about snippets of code. This helps uncover issues like deprecated search methods, incompatible date range logic, and submission vs comment searching. In the end, the fully functioning bot automatically scans new Reddit posts for prompts, cross-posts them to a new subreddit, and comments with the matched prompt text.
Takeaways
- Bing chat can generate Python code for building a Reddit bot
- The Python Reddit API Wrapper (PRAW) is used for Reddit bot development
- Bing gave step-by-step guidance on getting Reddit API credentials for the bot
- Print statements are critical for debugging Python code
- Asking Bing clarifying questions helps co-author better code
- Storing prompts separately allows revising and combining them
- Splitting up code into logical sections makes it more readable
- Bing doesn't get annoyed by repeated questions
- Bing suggested ways to work around prompt length limits
- Sharing code on GitHub allows others to reuse and build on it
Q & A
What Python module is used for accessing the Reddit API?
-The Python Reddit API Wrapper (PRAW) module enables Python code to interact with the Reddit API.
How can you debug Python code effectively?
-Add print statements throughout the code to output variable values and check program flow and logic.
Why store chat prompts separately from coding them?
-Storing prompts separately allows revising, combining, and reusing them more easily without hitting chat limits.
What was the issue with duplicate Reddit submissions?
-The code was cross-posting every qualifying comment, instead of checking if a submission already existed.
How can you expand the character limit in Bing chat?
-Bing showed how to increase the limit from 2,000 to 25,000 characters by altering the webpage HTML, but this may violate terms of service.
What is a benefit of posting code publicly on GitHub?
-Sharing code on GitHub allows others to reuse it for their own projects and build on it with improvements.
Why break code into sections instead of one long script?
-Splitting code into logical sections like functions makes it more organized, readable, reusable, and maintainable.
What flair tags helped identify relevant Reddit posts?
-The Showcase and Painted Over Edited flairs on /r/midjourney helped identify posts likely to contain prompts.
How did Bing assist in improving the Python code?
-Bing gave recommendations for fixes, optimizations, and fail cases to handle - serving as a collaborative coding partner.
Why allow the bot code to be publicly reused?
-Sharing useful code openly helps others learn and speeds innovation by building on previous work.
Outlines
Introducing the Reddit Bot Project
The video introduces a Reddit bot project to automatically find and repost prompts from the r/midjourney subreddit. It will use Bing chat to generate the Python code. The narrator provides background on Midjourney and the usefulness of sharing prompts. He explains the high-level goal of the project and bot.
Getting Reddit API Credentials
The narrator walks through the steps to get API credentials for the Reddit bot, including creating a separate Reddit account for the bot. He emphasizes keeping credentials private. An additional API registration is done though may not be required. The credentials allow the Python code to access and post on Reddit like an authenticated user.
Coding the Reddit Bot Logic
The initial coding process with Bing chat in creative mode is described. Debugging approaches like error messages and print statements are suggested. Bing's code is iteratively improved based on testing, errors, and the narrator's prompts. Functionality is added to search posts, handle errors, avoid duplicates, and meet the cross-posting objective.
Refining the Code
Additional improvements are made through prompts to Bing, including: searching post text, adding triggers, making triggers case-insensitive, optimizing performance. The narrator also cleans up the code by putting triggers in a set and renaming variables for clarity. The code structure is split to separate comment and submission searching. Flair filters are added.
Debugging Issues
Several examples are provided of debugging issues in the code by probing Bing for explanations of its logic and suggestions. This helps resolve problems with: duplicate posts, cross-post checks, trigger formatting. Bing's responses illustrate how it can assist with troubleshooting.
Tips for Working with AI
Useful tips are shared for collaborating with AI like Bing on a coding project. These include: recording prompts separately, being an active partner, using precise prompts, avoiding confusion on terminology, and handling code truncation.
Completing a Working Bot
The final steps are described including testing real-time commenting and ensuring all comment types are checked. The complete bot code is posted to GitHub. Future videos on deployment, logging, and maintenance tools are mentioned.
Interesting Bing Chat Hack
As an aside, Bing's suggestion to alter the HTML to expand the chat prompt size limit is discussed. This reveals Bing's intricate but limited understanding of its own interface.
Mindmap
Keywords
💡Reddit bot
💡midjourney
💡prompt engineering
💡crosspost
💡API
💡Google Cloud
💡coding assistant
💡print statements
💡duplicate posts
💡deployment
Highlights
Bing chat bot helps code a Reddit bot in Python to automatically find and share Midjourney AI image prompts
The bot scans the Midjourney subreddit for posts with prompts, then cross-posts them to a new subreddit
Coding bots with Bing chat using the Precise style focuses on factual, concise answers for writing code
Add print statements to Python code so you can see what the code is doing at each step
Write code prompts separately before entering them into Bing chat to refine questions
Q&A process with Bing helps debug code issues and understand how the code works
Supplemental mini programs checked for cross post ability and other functions outside main bot code
Check for code cut-offs in Bing responses and request the missing portions
Revised code to separately check submissions versus comments for prompts to simplify
Manual workaround code prevented duplicate cross posts of multiple comments
Final Reddit bot code posted to GitHub, next steps include deploying bot on Google Cloud
Bing gave HTML hack to expand chat response character limit from 2,000 to 25,000
Possible Bing doesn't realize it's interfacing through a browser, like a "brain in a jar"
Inspires coding your own AI-assisted bots for Reddit or other platforms
Upcoming videos on deploying, logging errors, maintenance checks for Reddit bot
Transcripts
this is my Reddit bot MJ prompt bot it
lives on the Google cloud and monitors
the mid-journey subreddit 24 7 for free
if you're curious how to make a Reddit
bot even though your coding skills are
Rusty or non-existent then keep watching
because my name is Michael and I figured
out how to use Bing chat to create my
first Reddit bot so I use the bot to
make a bot actually I used a bot to make
a bot to help people use another bot
let me jump right in and I'll explain
everything as I go along I promise Bing
is the AI chat bot I prefer for coding I
use it over the more famous chat GPT
because Bing is also free but doesn't
require a phone number and currently has
more capabilities than chat gbt you need
to have a Microsoft account and use the
edge browser for big chat there are ways
to get it working on other browsers but
I was fine with Edge I started by asking
Bing can Bing code in Python being
responded Yes so I asked if it could
generate python code for Reddit bot Bing
said sure and then talked about Pro
turns out pra is an acronym for the
python Reddit API wrapper which you need
to code a Reddit bot in Python I didn't
know about prop but Bing did thank you
bing bing also gave me sample code for a
simple hello world response bot Q at the
end it mentioned that my bot could be
deployed for free on a cloud platform
like Heroku to make it run continuously
this was wrong but we'll get to that in
another video so now that Bing and I are
vibing I hit it with the bot I want to
make I ask can you you code a Reddit bot
in Python that will find any comment in
the mid-journey subreddit that contains
the phrase imagine and was made by the
user that submitted the post and then
cross post that post as a new Post in
the MJ prompt bot subreddit and post a
comment to that new post that is a copy
of the found comment
what let me explain mid-journey is a
text to image AI that generates really
cool images based on text prompts you
communicate your prompts to Mid journey
through a Discord bot prompts are also
how I talk to the Bing chat bot prompt
engineering is an art and a science and
for image generating AIS it's a lot of
trial and error giving you only have a
finite amount of processing time with
mid-journey a good way to get better at
crafting prompts is by looking at other
people's prompts and the images those
prompts created then you copy the bits
of the prompts from the images you like
and build from there a popular place to
share mid-journey picks is the mid
Journey subreddit on Reddit but very few
posters include their prompts people
often complain about this on the
subreddit that's where my bot can help
mybot scans the mid-journey subreddit
and when it finds a post with a prompt
it cross-posts it to a subreddit I
created called MJ prompt bot it's the
same name as my bot before you can run
your code you'll need to get your Bots
credentials from Reddit Bing lists out
the steps here and I'll run through them
in the video so you can slow it down and
pause to see the details by the way
don't worry if your Reddit looks
different from mine I'm using old Reddit
with some plugins but I check the
current version and it's exactly the
same process you might want to create a
new Reddit account to run your Bot I
created mfiobot as my Reddit account for
my bot so if something went horribly
wrong it wouldn't mess up my main Reddit
account
you should also read the developer terms
and API terms there will be links to the
pages you'll see here when you click the
create app at the bottom of the page it
gives you your Bots credentials below
that you can see the same create
application form you just completed with
some of the fields already filled in you
can ignore that it's just there in case
you want to make a bunch of the same bot
for our purposes we just need the one
bot and now we have what we need it's
credentials but when you scroll down
you'll see there's a link that says You
must also register to use the API API
stands for application programming
interface and it allows your Python
program to interact with the reddit
website similar to the way you use the
Reddit app or the Reddit browser to
interact with Reddit to be honest I'm
not sure that the API registration is
required because you already have your
Bots credentials before registering but
I just didn't want to risk my bot not
working due to technicality so I went
through the whole process you'll put the
credentials from the page where you
created the bot plus your Reddit account
username and password for the one
controlling your Bot into your code to
create an authorized Reddit instance
this allows the bot to search and post
on Reddit the same way you enter your
ready a username and password before you
can post or do things on Reddit these
need to be private I'm showing mine here
so you can see what they look like and
where they go but I deleted these
afterwards and redid the whole process
off camera to get my bots real
credentials the ones I'm using now so
the code you see later on in this video
will just be using credential
placeholders I had one more step before
I jump back into coding because I
created the MJ prompt bot subreddit with
my main Reddit account and also made it
private I had to add my bot as a user of
that subreddit so it could post there
I'll make the subreddit public once the
bot is fully operational
back to coding Bing responded to my
prompt with some code I copy and paste
that code into notepad or directly into
a py file that's also where I make any
changes to the code that Bing suggests
later I run the code on my PC and in a
later video I'll show how I upload the
py file to the cloud so it can run 24 7
on a virtual machine so to code your Bot
with Bing you'll need to install python
on your computer I've seen Reddit bots
in action but I didn't know how they
actually searched Reddit so I asked Bing
and found out my bot was coded to search
new posts as they are made that might be
fine when the bot is up and running
perfectly but for testing it meant I
would need to wait for new posts that
had prompts in order to know if my code
was working I hate with
me too an ego so I advise the code to
search a date range then I ran the code
for the first time I actually thought it
would work so I recorded myself here it
is
okay
and nothing happened okay
all right let's try to figure it out
Pro tip run your code from the python
editor instead of just running the pi
file so you can actually see the error
messages in the python shell now that
you can see the error messages you can
copy them and paste them into Bing to
debug your code sometimes I say here's
an error I received and I paste it in
and other times I just copy it into the
chat and Bing realizes what I'm asking
especially when we're already discussing
the code my first error was having a
quotation mark in the bot's username
which messed up the credentials my
second error was that I didn't install
Pro took me a while to realize that it
needs to be installed from the Windows
command line not the python editor Bing
help me with that but even after fixing
my newbie mistakes the code still
produced an error so I plug the error
into Bing and it told me the search
method in my code was depreciated and
would be removed in the next version
that was annoying because I don't want
to have to change the code when Pro is
updated but I expect the issue was
caused by using the creative style Bing
chat has three Styles the creative mode
generates longer more imaginative
answers while the precise mode focuses
on shorter factual answers the balance
mode aims to provide a balance between
the two Styles these styles are very
important I started using the creative
style to write my code but later learned
if you're going to write code precise
style is the way to go you can tell
which style you're using based on the
color purple blue or green
after a few iterations my code ran
without errors but didn't cross post
anything oddly I could not figure out if
the date range was correct being in the
internet gave me conflicting answers
it's possible I was checking dates in
the future that didn't have posts yet or
posts too far in the past so I had Bing
revised the code to post in my subreddit
if the bot did not find any comments in
its search and it posted this was a huge
relief because I knew if it could post
it could search now that I knew my bot
could work I started over with the
precise style but the same prompt being
used a different approach and set up the
code to search the first 10 new posts
this meant the code would check the 10
most recent existing posts so I didn't
have to wait for new posts to come in
and no more messing around with wonky
date ranges still no cross posts so Bing
suggested a print statement let me see
what the bot was checking brilliant and
that's another Pro tip you should always
add print statements so you could see
what your code is doing comments which
are anything after the hash or pound
sign are also a lifesaver Bing suggested
opening up my search criteria to trigger
words and comments by any user but I
knew the original poster of the picture
would be the only one able to comment
with the real prompt so I ignored Bing's
suggestion here I switched my code to
search hot posts as I figured these more
popular upvoted posts had a better
chance of having prompts in the comments
but I got an error with Bing's help and
the print statement I could see it
crashed because the code was checking an
announcement post made by a moderator
those posts don't register as having a
proper author so Bing was able to fix
that by checking if there was no author
and skipping those posts once the error
was corrected I got my first real cross
post this is exactly what I wanted it
even commented with the prompt I asked
Bing to suggest more triggers and it did
it also added them to the code without
me even asking I also added that the
trigger should be case insensitive
meaning that if somebody capitalizes any
of the letters my thought will still
pick them up this reminds me don't be
afraid to tell Bing to clean up the code
here I noticed it was repeating my
trigger terms in each Loop so I asked
Bing to put them all into one set and it
did in my final code I settled on
imagine prompt and the Double Dash often
used in mid-journey prompt codes and I
removed any slashes or colons because
although the mid-journey bot uses them
in its prompts sometimes people don't
include them when posting their prompts
to the mid-journey subreddit later I
noticed a post that had the prompt in
the text of the post itself rather than
in the comments I wanted to search that
text so I plugged the link to that post
into Bing and asked it to tell me if it
would trigger my code to cross post Bing
could see the post I was referencing
even though it was only made recently
and basically ran my code on it it told
me that my bot would not catch this post
so without me asking Bing provided the
revised code to include the submission
self-text in the search for prompt
triggers then Bing suggested that this
change might catch posts without prompts
such as question or discussion posts so
it added the prompt flare as a search
criteria for posts Reddit flare is a way
of tagging your posts with a label that
helps categorize it question and
discussion are flares that are used on
posts in the mid Journey subreddit stop
for a second and think about how Wild it
is that Bing seemed to get what I was
doing so well that it could actually
make this suggestion I was blown away
but then I checked and I found the
mid-journey subreddit doesn't have a
prompt flare so I told Bing to remove
that from my code this is a great
example of how much AI can do and how it
can stumble I later added a flare check
back in for the Showcase and painted
over edited flare I also checked to make
sure the mid-journey subreddit wouldn't
let you post with flair being blank just
in case I needed to check for no flare
luckily Flair is required so I didn't
have to allow for that in my code keep
in mind that you're co-authoring the
code with Bing working together to
complete your project you need to have a
general understanding of how the code
works so ask questions as you go along
here I asked Bing why it added a break
at the end Ben gave me the stock answer
from the broad documentation that the
break statement is used to exit a loop
prematurely but then it said in this
case I added it to stop the bot from
checking more replies to the thank you
message after it has deleted the cross
post this is to avoid unnecessary work
and potential errors explaining why it
used certain statements is fantastic for
Learning and understanding your code by
the way this was for code I considered
adding to notify the original poster
when my bot copied their post and
allowing them to potentially delete it I
eventually scrapped it when I found out
Reddit automatically sends you a message
when your username is mentioned in a
comment another way this helps is the
closer you get on the language the more
precise your prompts for example I was
calling these posts but I learned Pro
calls them submissions so when talking
with Bing from now on I started calling
them submissions to avoid any confusion
more importantly this q a process helped
me debug an issue that plagued my code
for days while trying to prevent
duplicate cross posts the code would
check if the cross posts existed in my
MJ prompt bot subreddit and whether it
was cross-post-able I questioned Bing
about it but it didn't click for me
until I wrote a separate program to
check for cross post ability and it came
up false for all my posts I finally
realized the cross postable test was not
only be completely unnecessary because
it was being run on submissions already
in the MJ prompt bot subreddit but it
was also always false then confirmed my
view and removed it I've made a few
supplemental programs to help my bot but
I'll go into those in a later video and
remember unlike a person Bing won't get
annoyed and stop helping you it even
ignores spelling mistakes like here
where I typed Cod instead of code it
knew I wasn't talking about fish by this
point I learned so much that I started
all over with being using a big prompt
incorporating everything I learned so
far this was easy because I've been
recording my prompts and Bing's
responses in a separate Word document I
would say this is another Pro tip write
out your prompts separately like in word
or notepad before putting them into Bing
chat this lets you revise your prompts
break them up or combine them and also
reuse them if you hit the 20 prompt
limit but be careful somehow doing this
caused the Double Dash trigger in my
code to become a single long Dash
causing it to miss several prompt
comments you can even see it here before
I caught it much later took me a long
time to find this one so be vigilant so
now my bot will check new comments as
they are made in the mid-journey
subreddit instead of checking
pre-existing comments this is how my bot
is supposed to work on the cloud which
is my ultimate goal so I first need to
make sure it will work this way on my PC
at home I ran the bot and posted a
comment to one of my submissions to the
mid Journey subreddit checked for a
cross post to my MJ prompt bot subreddit
and success now that the comments were
being checked properly I asked Bing to
add code to check submission self-text
as my old code had after adding that I
noticed there was a submission with the
prompt in the title so I asked Bing to
cover that too I had some issues and
even checked my version of prop couldn't
figure out what was wrong so I told Bing
and it rewrote my code to search
comments and submissions separately this
is the basis of the actual code my bot
uses now and the split makes things
easier to understand when looking at the
code itself now that the bot was
checking comments and submissions
separately I wanted to make sure only
comments to submissions with the
Showcase or painted over edited flare
were being checked this was in the
submissions check but I never asked Bing
to put in the comments check until just
now here's another Pro tip sometimes
your code will get too long for Bing's
response box and it'll cut off before it
gives you everything if that happens you
can simply tell Bing to just show you
the part of the code that's missing
either to say give me the last half or
give me the piece after and then give
some code where it cut off I noticed
that when there was more than one
comment in the same submission that
triggered my bot it would cross post
each comment to a new submission in my
subreddit making duplicate submissions I
asked Bing to check this in my starting
over prompt but it didn't work I checked
back and saw my prompt was a bit unclear
on this point so I again asked Bing to
revise the code so that before it cross
posts a comment it checks the MJ prompt
bot subreddit to see if the cross post
submission exists and if it does it
cross-posts the comment to that same
submission in the MJ prompt bot
subreddit but it didn't work and Bing
suggested checking for existing cross
posts manually I thought it meant for me
to check it myself with print statements
or something so instead I tweaked The
Code by making cross posts singular in
one line of code because it looked that
way in other lines I got another error
and I told Bing what I did Bing
explained to me that what I did was
completely wrong because I made it try
to cross post and we're checking if a
cross post already exists being reminded
me the code that it already suggested is
a workaround that checks for existing
cross posts manually it gave me the
suggested code again finally realizing
that it meant the code would manually
check for cross posts I used it sure
enough Bing was right I made three
comments to my sorcerer or Barbarian
Post in the mid-journey subreddit and my
bot picked them up and cross-posted them
into the same submission on the MJ
prompt bot subreddit then I stopped the
bot and re-ran it added a new comment to
my submission and that fourth comment
was also cross posted into the existing
post on the MJ prompt bot separated now
my bot was complete I'll post all the
versions of my code to GitHub and put a
link in the description below I've had
so much fun making this bot it's such a
great feeling of accomplishment to get
it up and running I hope the video
inspires you to try it too in later
videos I'll cover uploading and running
the bot on the Google for free getting
the bot to log what it's doing and any
errors it encounters and creating
maintenance and checking tools for the
bot so like subscribe and hit the
reminder Bell to get notified when I
post those videos and as an added
benefit for those of you who have stuck
around to The Bitter End here's a crazy
hack at some point I hit the 20 question
limit while still working on my code I
tried to copy and paste it back into
Bing via the prompt box but it was too
large I asked Bing how many characters
can fit in the prompt box and it told me
only 2 000 characters but then being
volunteered to show me how to expand
that to 25
000 characters by altering the HTML of
the page this fascinated me why was it
allowed to do that my guess is that Bing
chat does not know that it is
interfacing with you through the Bing
chat webpage on the edge browser but it
knows there's such a thing as the Bing
chat webpage because people talk about
it on the web Bing is like a brain in a
jar that knows what a jar is but just
doesn't know that it's in one
you don't know no I don't I'm not
recommending you do this because it
might violate the terms of service I'm
just pointing out something interesting
I found from Bing chat happy coding and
I'll see you in the next video
Ver más vídeos relacionados
![](https://i.ytimg.com/vi/zUBXBeqHFkQ/hq720.jpg)
The Perfect Prompt Generator No One Knows About
![](https://i.ytimg.com/vi/5H5Yxpj9imU/hq720.jpg)
Ücretsiz Dall-e 3 Kullanarak Prompt Girmenin Mantığını Anlattım
![](https://i.ytimg.com/vi/zqVtHYFYQY8/hq720.jpg)
ChatGPT Tutorial 2024: How to Use ChatGPT - Beginner to Pro!
![](https://i.ytimg.com/vi/xsK4uATpxLY/hq720.jpg)
Всё о новой нейросети GPT-4o за 7 минут!
![](https://i.ytimg.com/vi/4mHMsnt3TIQ/hq720.jpg)
Find hidden gold mines that make you money
![](https://i.ytimg.com/vi/C2DPGWVii_Y/hq720.jpg)
[The NO Prompt Method] MULTIPLE Consistent Characters with Custom GPT & DALL-E
![](https://i.ytimg.com/vi/nMok0XXrT24/hq720.jpg)
How to Use DALL.E 3 - Top Tips for Best Results
5.0 / 5 (0 votes)