Code a Discord Bot with Python - Host for Free in the Cloud
HTML-код
- Опубликовано: 19 июн 2024
- Learn how to code a Discord bot using Python and host it for free in the cloud using Repl.it.
🚨Note: At 16:43, Replit now has a new method for environment variables. Check the docs: docs.replit.com/programming-i...
Along the way, you will learn to use Repl.it's built-in database and create a Discord bot that uses webhooks to connect with GitHub.
Need help with this tutorial? You can ask questions here: forum.freecodecamp.org/
This course was developed by Beau Carnes.
🔗 Online code editor: repl.it
🔗 Discord Home Page: discord.com/
🔗 Discord Developer Portal: / discord
💻 Python server code for bot: gist.github.com/beaucarnes/51...
💻 Full code on repl.it: repl.it/@BeauCarnes/Encourage...
⭐️ Course Contents ⭐️
⌨️ (00:00) Introduction
⌨️ (01:18) Creating a Discord Server
⌨️ (01:52) Creating a Bot User
⌨️ (06:05) Starting a Project in Repl.it
⌨️ (09:33) Coding a Basic Discord Bot
⌨️ (20:14) Improving the Bot
⌨️ (33:35) Using the Repl.it Database to Store Bot Settings
⌨️ (56:09) Testing the Bot
⌨️ (58:42) Creating a Web Server for the Bot
⌨️ (1:03:36) Connecting Uptime Robot So Bot Runs Continuously
⌨️ (1:05:21) Creating a GitHub Discord Bot Using Webhooks
Special thanks to Repl.it for providing a grant that made this course possible.
--
Learn to code for free and get a developer job: www.freecodecamp.org
Read hundreds of articles on programming: freecodecamp.org/news
At 16:43, Replit has a new method for .env: docs.replit.com/programming-ide/storing-sensitive-information-environment-variables
The Python Discord library used in this video is no longer being updated. Consider making your bot in JavaScript: ruclips.net/video/7rU_KyudGBY/видео.html
help -please
help me add quote web?
Hey I Removed Random Command because I Wanted to get the value Directly Full Value But I Get [ " Text "] like this only how to remove that bracket And Get Text Alone
you are so late for this news🤣🤣🤣🤣
@@jx3715 😂
Me: im depressed
Bot: nice
very sad!! #Thug_life_Bot
Lmao, ikr
the best bot lmao
petition for discord to verify this bot, anyone?
Should name it no feelings bot i mean its true
Went through the first 20mins of this with my 13-year old and they are delighted and excited to have coded a live bot that does what they want on their discord servers. Great work with this tutorial. Thank you!
i wish i could say the same
Wow you're a great dad
great dad, lucky
you dont seem to know your 13 yo's gender
@@sweetmelon3365 some people use they/them pronouns. or maybe he doesn't want to disclose their gender to a bunch of yahoos on the internet. either way it's none of your business
There may soon be more bots on Discord than people. :)
First reply. Deez Nuts
Second Reply. Candice
Third reply Kenya
Fourth reply. Ligma
8th Reply
Bro, I love this guy! He doesn't make his videos sound boring like some other tutorials.
58:19
*i am depressed*
*_nice_*
this bot is a genius
What I want to know before going through this
@@sivasaran4 Its like this because NLP (natural language processing, a form of AI), isn't used here, and we are simply coding in the text
@@ishanchoudhary4179 ok, I want to know basic django because he not explaining all
@@sivasaran4 umm this video isn't about django
ehy cant i create a .env file
What an INCREDIBLE video, no corners cut, actual teaching, congratulations freeCodeCamp, you've done it again!
i just got on my adhd meds for the first time and this was my first project. I struggled with focusing on stuff like this for a long time. It was like 'blah blah blah get to the point' but this was a really great learning experience for me and I got to make something fun and neat and i've even made my own list of gifs that post randomly when a certain word has been said. thanks so much!
This is such a great tutorial! Literally people with 0 experience in discord bots can start, maybe even people totally new to python. And it includes the whole package of all the essentials, the framework. Most RUclipsrs split this up in like a gazillion videos in a playlist, but this video absolutely dominates them all!! Thank you so much!!!
Well if you know nothing abour python, jumping straight into making discord bots isnt gonna help, heck, i made a few programs in python and im still not gonna be able to code a bot all by myself.
it doesn’t work for me
I would know i didnt even know how to make it lol
Coded my own bot for my discord server and yeah this is by far the most easiest and simplest tutorial on how to make a discord bot ! Great work man expecting more tutos from you!
I'm very broke, but really love making these bots. You sir are a life saver for showing us we can host the bot off-site. You've earned a sub
Amazing turtotrial. In one hour I've learned how to use discord bot documentation and keep it running 24/7 as well as having a free database! You sir are an angel walking in man's shoes.
Thanks for this - as a software developer (who works mainly in the linux/cli environment) - a lot of this stuff is new to me. So I really appreciate you walking us through it step by step.
I haven't coded anything in a long time, and haven't coded anything in python. This tutorial was great, thanks for making it!
BROO THANK YOU SO MUCH, i already did the basic bot before but you helped me with responding to messages function.
It's awesome how I understand these functions now, 5 months ago I started studying Python, thankfully now I know a bit
Nice!!
im trying to start out coding in python,any tips of how to start as im kinda overwhelmed and dont have any where to start
@@wyvern- For me, having a goal is what keeps me motivated on coding. Join a coding community for beginners so that you won't feel lonely or stressed. And sleep early then study once you're awake, but don't forget to do other things that hits your interests... it's always good to have balance
@@dreamteamextrayt o
Just started learning last 2 weeks ago, have 0 clues what he's saying, I only know import and function
This man just made my day. I always wanted to created a bot but I just started learning Python and I'm still learning basics and control structures. So I don't know where to start but this guy helped me how to do the bot in every single step and yes I did it! Thank you so much, I hope you'll do some great videos like this which are very helpful! 👏
I was actually looking for a tutorial like this. This came in at the right time
this is so crazy! This video pops up a couple days before I need it! Thanks so much was really helpful !
I have to say, you make coding seem alot less intimidating, good job
Want to add, thank you for this tutorial, its still super helpful in 2022 ( with some fixes ) and gave me an idea on how to use Webhooks and so much more, thank you for all the free resources! :)
This is one of the best series , should make a part 2
When it sends the inspirational messages it put them all together
Managed to get it working and finish! Will try to improve it and personalize. Thanks!
Time to create my search engine bot thanks to you
Lots of respect to you (also to replit for keeping that ping flaw)
Me: Let's code a discord bot during the winter break
This GOAT channel: I got you fam!! Video's on the way...
This
what does goat means?
@@tfolz1351 Greatest Of All Time
Iv been waiting months for the perfect video and I finally found it
What a fantastic video. Thank you so much for this! I worked out the little things that had been depreciated, and a couple of times my indents were off which was throwing me off...
I used to code in C# a couple of years back, but no experience in Python. Now I'm really warming up to it! Thanks again, the bot works great.
Your tutorials are appreciated. You explain everytNice tutorialng so simply and show the fundantals of producing. Many people and myself thank
In the introduction, it sounds like he has a gun to his head and is being forced to read the introduction script as fast as he can.
lol
he always talks like that it's hilarious
That's just how dude talks, he spec'd into intelligence not charisma
@@chrispysaid lol
Oddly specific…
This was perfect tutorial i was looking for
THX verry much, i made my first simple bot by js but soon after that every thing was ruined by errors, but with python every bot runs perfectly FINE! THX VERRY MUCH!
i love how every turtorial i follow i always end up failing
same broo :(
coding right? i cant learn it either
i failed in "async def on_message(message):"
Things have changed on replit since this tutorial was released. Try a discord bot tutorial that is newer: ruclips.net/video/zGy2muWlE5A/видео.html
@@beau thx bro iam not home but whene IAM home IAM gona try it 😁😁
Me: I murdered someone's parents and made him miserable
bot: You're a great person, cheer up!
i love this statement! The bot forgave the both of us for what we did! :D
LMAO
lol
@THE_07 indeed
@Clockza 😮
Really nice video idea! As I skipped trough the video, I noticed that you put all the code in one file and for commands used the 'on_message' event. Might be good to show the community how to work with cogs!
Please help. I am trying to make commands using @client.command() after setting the prefix but it is not giving any output on the discord server
@@yamdagni hey! Sorry for the late answer, I was a bit in a hurry today. Anyway, where exactly does the error appear?
@Sarguhl I have fixed it after trying for 3 hours.
TheIr was no error in the console upon running.
The @client.command() just didn't work for some reason. I set the prefix as + and wrote a command. But when I put that in the discord it wouldn't give out any output, there was no error in the console either.
Turns out that for some reason, adding this:
@client.event
async def on_message(message):
message.author==client.user:
return
Was what was preventing it. I removed that and it all worked again
I was going to make a discord bot and searched up a tutorial and found this masterpiece thank you for making this :)
Good tutorial, was able to follow along and make alterations with no issues. Thanks for sharing!
@Anime lover Hey, I had issues with ensuring it's appropriately spaced, so I'd check that first! Good luck!!
this is a really great video! i wish there were more features explored though :) thank you for posting this!
This was really helpful! Thank you so much!
Hey, I've been learning python for bot making. This helps a lot, I would recommend it to other people!
can you recommend playlists on this topic for me I'm super super interested
i am a swift/iOS Developer, i must sat that *"if any(word in msg for word in sad_words): "* got me into python and am gonna learn it asap.
Great tutorial btw !
Just few days ago I was trying to find how to do this.... Its like my wish is their command
nah it's tracking they track all our data and everything
Now you are gonna get thousands of likes😄
Haha, Just yesterday I was researching the same thing.
Agreed...But for freecodecamp to actually post a video about that... That's what I meant. I have anyway subscribed to every video they post... Love the channel
@@pixel2054 haha fitting that pixel says it...
Thanks for the video :D
1:08:18 I found it funny when you need to create your own event after 5 days, then actually get an event while recording
I use it in my project and it works.Thanks for your sharing.
thank you so much this is the only in depth tutorial i've found
I award you year's best tutorial.
I needed it for my school server. Thanks fcc :D
what
we both are the same
If you get an error when you use
options = options + db["encouragements"]
I has an error using this
try using
options = options + db["encouragements"].value
I think why by adding .value it works is because in the earlier statement we were trying to concatenate a list/array with a dictionary kind of thing which had {value=[//Your message]}. By adding value I was able to concatenate the message to the database.
tysm man i was looking for this comment.
Omg yess, finally.
this sadly didnt work for me
Thank you!!!
You are amazing
Finally finished this tutorial. Had to modify some lines here and there, but overall pretty good!
bot didn't work next day bc discord blocked replit bc it did too many requests rip.
@@Jawsnpie lol ... what did you make the bot for tho? I just made a bot that could generate memes
Love the way this man says "button"
Hahaha
could you put a timestamp to when he says it?
@@liannea4609 2:21
bahten
To be honest, this is amazing. It teaches us everything, the video isn't too short to make you think you learned something when you really just copied code and it isn't too long to make me quit making a bot. Thank you!
Legendary tutorial, thank you sir!
Thank so much my GTA staff team is thankful for it cause we got tone of member that can bypassing everything we put in there way! (edited my server has it own website)
Great tutorial. Very through and helpful!
This video helped me out a lot. He explains it very well, in a very understandable way.
Agreed. Absolutely
It's pretty amazing how much replit can change in just two years
Thank you, this video helped out a lot!
If there is an issue with the intents, or if your bot is not responding where you put in everything as is in the video, replace the client line with the following two lines:
intents = discord.Intents().all()
client = discord.Client(intents=intents);
wow thank you so much you are so cool whichever lady ends up with you i bet she is going to be extremely happy but just remember bros before hoes
Remember to also toggle ALL privileged gateway intents in the discord developer portal! Otherwise it won't work lol (took me too long to figure out)
good point there frfr
@@pepememe6561 You da MVP man, ty
you are a life saver! thanks man!
Replit just changed the hosting method, they need to pay money to hosting in Replit Deployments as a new hosting feature instead of using flask method. :(
Hands down, the most exciting python lesson I've heard! You're the best, sir.
Im having trouble with await message.channel.send() it says syntaxerror: ‘await’ outside function?
@@reardonsvids7195 same
Organized tutorial, thank you!
Thanks for the tutorial! What can I do if I want my bot to send images or if I want it to speak? What libraries can I use?
I actually just finished setting mine up. If only this was uploaded a week ago xD
INCREDIBLE video .. Thank you so much FCC ❤
Thank you very much for your tutorial; you saved my life!
Thanks, I really Needed it for my discord Server
this is a very good tutorial, although I only used it for making my bot being up always
same lol
The moment it actually worked and replied to my message felt really really good :D
This encouraging bot is very encouraging!
~ Beau Carnes, Dec 15, 2020
Can you pls make another part?
There are so many things we still need:
How to React
How to Reply
How to Send Images
How to get Data like Names
How to apply Roles
etc
You should read the docs
Hey, i've a issue, when I try to start the bot and click the button "RUN", it starts and then turn off without saying anything in the console. Any solutions?
Amazing tutorial man!👌🏻god bless
Thank you-
I was SUFFERING because of my friends instruction
I don't know if this comment is going to make this to the top but, they have created something new on the side bar. It's called "My Secret". It looks like a lock. When you click it, they will give you directions. First you put the name as "TOKEN", if that's what you want to call it. Then you would put the value of it below it (token). Then hit create. It gives you a option to import the easier way which is what I did.. Hope this helps :)
great video! any chance you can help with adding a trivia section to this?
Thank you chief, helped a lot.
Since I use python for programming this will be useful!
People who are getting:
File "main.py", line 3, in
client = discord.client()
TypeError: 'module' object is not callable
See that you have left space between the command in the starting. Look at the spacebar line in his code and yours.
Or it's because its discord.Client() with a capital C
This guy is a legend!
That's a sign that this actually works...
I have done nothing with my life :(
Thank You, This is incredible!
I recently did this myself. Was really easy.
Soooo... the server I hang out is normally never (with seriousness) toxic. However... Knowing this crew... I'm sure that allowing them to add their own words of 'encouragement' is really really going to turn out to be hilariously not encouraging. haha.
Or even worse, instead of encouragement or not encouragement they could make the bot send other stuff such as gore, porn and everyone pings
why do i always find these videos at 10pm
Same lmao 😂
Samee
very helpful tutorial, thanks!
i think im gona keep this video and watch it later, this sounds good.
There are many outdated things here, it'd be nice to see another tutorial on how to make a bot with the changes that ended up happening. For example, my bot isn't working because apparently there's an ObservedList
Haha! Time to update Linkedin profile!
i will count this 1 hour of my life as one the best
rly good tutorial just takes some time and is a bit difficult over all but still is very good
If anyone has a problem with the line : options = options + db["quotes"], youll have to change it to: options = options.append(db["quotes"]). You can only use append to add something to a list.
this help me a lot i stuck in this line for 3 hr
@@kasquisaliq2910 u get how to solve...if yes then tell the solution......plzzzzzzz
@@DeepakSharma-ug3ij this work for me options = options + db["encouragements"].value
sry I'm really busy but you can ask me anything
@@kasquisaliq2910 i got already solution that is :
option+=db["encouragements"]
easy
Yo, what's good homie? I ain't got no problem with that line. You just gotta use append to add something to a list, ya dig? Ain't no thang but a chicken wang.
You are/were not alone! I pray you found what has worked for you!
Thx man, helped a lot❤️❤️
won't work for creating won't say we have logged in as (name) bot
@@stephennovak8083 did you fix it yet
@@Audioandlyrics nope, still won't work
@@_ahn9631 hey could you send a permenant invite so I could join?
@@_ahn9631 can you help me won't say we have logged in as (name) bot
@@_ahn9631 the discord link wont work! can u help me?
What, i didn't know repl could host continually running code
There's a new feature called Always On for hacker users
@@tahini245 Oh a new feature for repl? what does it do?
@@Soda-js2vx It's just the thing without pinging the repl whole time
thank you for this amazing tutorial
Thank for help! Now i have created ColaBot to my Cola server!
if you're coming to this video and you see that Repl.it doesn't have the .env file anymore, go to the left sidebar and click the lock icon labeled "secrets" and enter a key (ex. TOKEN) and the actual token for the bot in the box below where you enter the key name and enter that in. once you're back in your main.py the code you enter isn't client.run(os.getenv('TOKEN')) its
my_secret = os.environ['TOKEN']
client.run(os.environ['TOKEN'])
i got tripped up by that but that code seems to work flawlessly for now ^_^
Why does it says nameerror: “os” is not defined, what should i do
@@justnbody.5934 Make sure os is imported at the top by typing
import os
THANK YOU THANK YOU THANK YOU THANK YOU THANK YOU
In place of client = discord.Client() , use..... client = discord.Client(intents = discord.Intents.default())
Thank you bro so much. I been stuck here for so long. What does this code do since he didn't explain this in the video cause I think this might be a new update
Thanks dude!
This was surprisingly easy!
Thank you cdoe camp my little son learning so much here you all are super stars thank you so much