Code a Discord Bot with JavaScript - Host for Free in the Cloud
Vložit
- čas přidán 28. 05. 2024
- Learn how to code a Discord bot using JavaScript / Node.js and host it for free in the cloud using Repl.it. You will also learn to use Repl.it's built-in database.
🚨 At 13:44, Replit now has a new method for environment variables. Read what to do here: docs.replit.com/programming-i...
🔗 Get 3 months FREE of the Hacker Plan on Repl.it (first 1000 people): repl.it/claim?code=tryalwayso...
This course was developed by Beau Carnes.
🎥 Code a Discord Bot with Python Video: • Code a Discord Bot wit...
💻 Full code on repl.it: repl.it/@BeauCarnes/Encourage...
🔗 Online code editor: repl.it
🔗 Discord Home Page: discord.com/
🔗 Discord Developer Portal: / discord
🔗 Discord.js library: discord.js.org/
Need help with this tutorial? You can ask questions here: forum.freecodecamp.org/
⭐️ Course Contents ⭐️
⌨️ (00:00) Introduction
⌨️ (01:38) Creating a Discord Server
⌨️ (02:27) Creating a Bot User
⌨️ (06:23) Starting a Project in Repl.it
⌨️ (08:37) Coding a Basic Discord Bot
⌨️ (15:44) Improving the Bot
⌨️ (26:35) Using the Repl.it Database to Store Bot Settings
⌨️ (46:08) Testing the Bot
⌨️ (50:22) Creating a Web Server for the Bot
⌨️ (55:06) Connecting Uptime Robot So Bot Runs Continuously
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 13:44, Replit has a new method for .env. Read what to do here: docs.replit.com/programming-ide/storing-sensitive-information-environment-variables
Also, with Discord.js v13 there is more setup required. This quick video shows the new method: czcams.com/video/zGy2muWlE5A/video.html
Thank you, i was confused
idk what to do now :( can someone help
please help me
help
i got error on running
Stranger: which school are u from?
Me: FreeCodeCamp
Oooo
W3SCHOOLS 🤤
@@Saidur07 Yea lmao, but FreeCodeCamp has such a huge community.. I love FreeCodeCamp alot lol... But I respect your resources and opinions too as they fit your requirements 😀👍
@@asce313 yeah true......
I was kidding 🤐
@@Saidur07 g.
I've been looking for that yesterday and boom! My favourite code learning channel delivers.
You guys are amazing!
I absolutely adore this channel, I learned more about coding languages and algebra/calc here than I have in my entire life in school! *It's a blessing that it's all free too!*
facts lol we just need the paper and we will learn from here
I love when you make Discord Bots. I am a big fan of Discord and I really as well love it when Beau Carnes is teaching since he is a sooooo good teacher when it comes to programming
Your misspellings and typos actually make the tutorial more understandable, thank you for the great content
Also your name reminds me of that nosleep series
We want more beau stuff, he is an awesome teacher!
Very awesome for sure!
I've looked at his courses in the past - they're great :D
Is he founder of freeCodeCamp or ?
.env is not working out for me
@@karlobabic8495 yes.
What a high level of energy he has so much needed in this type of enthusiasm in our professors.
tysm man, I've been looking for a tutorial everywhere, this was the most helpful one!
The style of explanation is incredible! Its like he speaks the Code... never seen this before. Everything makes sense perfectly. Thanks a lot
Was really waiting for a video like this!
Yeah we know already...
In your package.json, update
"dependencies": {
"discord.js": "^12.5.3"
}
and the tutorial will go smooth for you, without worrying about the updated versions of discord.
I have succesfully completed my bot using this tutorial 2 months ago. Thank you!
Really awesome and straight to the point! Looking forward to learning more from you
Thanks, the 24/7 hosting actually works. Thank you!
Best channel I have ever subscribed and gained more experience by taking it's courses without wasting money, j come from hero to zero and now working with a company gained every month 180-230 Dollar
Thanks for you guys
I think that teaching programming with Discord and any type of software used in our free time with friends on the internet is the best way to start and understand what we are able to do with coding, great video and great channel, learned alot with y'all
Such a perfect tutorial! i thought it was harder to create discord bots, but it's so easy! Cannot wait to create my own ones.
34:46 click on the auto-format icon available at the left side of the console tab to format code.
TypeError [ClientMissingIntents]: Valid intents must be provided for the Client.
at Client._validateOptions (/home/runner/DiscordBot/node_modules/discord.js/src/client/Client.js:480:13)
at new Client (/home/runner/DiscordBot/node_modules/discord.js/src/client/Client.js:78:10)
at Object. (/home/runner/DiscordBot/index.js:2:16)
at Module._compile (node:internal/modules/cjs/loader:1105:14)
This was a great tutorial! Thank you so much!!
Thank you!!! I learned so much of the syntax I feel like I can do anythinng
I thought I recognized your voice! You're the guy in the hint videos
What hint videos?
@@cynapse993 on the freecodecamp website. In the coding practice exercises
@@amazingdestroy yes, he is the founder lol
Someone deaf and blind disliked the video unintentionally, he wanted to like it as well...
I already know this video is gonna be perfect for me 😂
Never have I ever been so early, and damn, a discord bot? Wow lol
This is the video i was waiting for
I was also
I recommend you guys to use a command handler as its much easier to sort out commands
I'm glad this channel exists.
When I press run, in the console unexpected token comes and the bot doesn’t come online
Followed the tutorial exactly but can't get past 15:00 as it crashes when I press run. The console says the problem is in discord.js but we didn't touch that so what's going on?
Error:
/home/runner/MobileSnappySourcecode/node_modules/discord.js/src/rest/RESTManager.js:32
const token = this.client.token ?? this.client.accessToken;
^
SyntaxError: Unexpected token '?'
@@str.1337 How to change the version to 12.5.3?
When He Said "Coding A Bot With Python" i went BRUH
I claimed the free 3 month hacker plan, thanks FCC!
Awesome video thank you very much. Would love to show you my work some day
That uptime robot trick was slick :)
Most of these channels dont Include to put in Intents in the "const client = new discord.Client({ intents: ["GUILDS", "GUILD_MESSAGES"] })"
If you don't include these, it will not work and throw up an error
thanks for the info very useful
thnx bro
You're a life saver- thank you
copied it from overstack flow? haha
@@guli_build2330 everyone does;)
to those who are struggling with the responding message which is not showing responding is true change this line ..
value = msg.content.split("$responding")[1].trim()
just add .trim() on value
Every thing was fine in this video except your light theme
Thank you, Beau. This tutorial was really good and surprisingly simple and easy to follow! The way you explained the mess of arrays at 19:42 was easily understandable. Hats off to you
Thank you so much !!!
Great tutorial sir... very helpful...
I already know how to make an discord bot in JS, but I love being able to see Beau!
can anyone help me
replit doesn't allow to create .env files anymore ...what to do
@@rome6323 On the left side menu click to the padlock 🔒 icon
@@GPeti07 hi
what would I need to add to have the bot send images? I can only find stuff for python and the stuff for javascript doesnt seem to work with replit
Can you make a more advanced bot that can do things like a currency system or send pictures?
Basically just a part 2 of this
You are Great Sir and channel and very good for us .
just completed the bot thanks for the tutorial
Thank you!
I plan to use Java and integrate Spring with my bot... Could u pls make a video on how to use the Discord Java API?
This is a great video!
If you guys ever remake this video I would recommend maybe just showing the returned object so we can see where the q and a came from.
I have a small question, each time i put the token into the index.js file it brings up an error, says that it cant read the token properly and in the error it quotes a part of the token in between two periods, if i remove the periods it says invalid token, what do i do?
Idk who this guy is but I wish he was like my 2nd dad or something this was fantastic.
btw if you're having problems around 11:30-11:40 it's because its not an apostrophe, its under that squiggly line at the top right next to the 1 of your keyboard.
aka a Grave accent
God bless
this was helpme......thnx
Lol thanks this guy isn't really explaining he's just speaking
@@andrew3606 Not really, he’s explaining this very well. It’s just that most people don’t know how to code or barely do and wanna make a discord bot, those types of people really can’t be helped, a discord bot is not a beginner project.
When I run the server on the bot, I get an error in console saying the port used for this is already in use, 3000. What do I do?
Amazing !!
Maybe next I should make it so those robots in the background in the intro can talk on Discord.
yeeeeeeeeeeeeeeeeeeeeeee boiiiiiiiiiiiiiiiiiiiiii
yes please
Hello, for some reason I might know why but the token for the bot doesn't work. Like old .env file due to Replit updating to not doing .env anymore and making 'Secrets (Environmental variables) in which you create a title for your token then insert a value which will corresponds to that title so that value would be the token you got from Discord developer site. Edit: If you have any solutions then feel free to reply.
Can you make a series on how to make a discord.js bot, so like moderation commands, economy commands etc.
@@areeb5160 YESSS Please create videos or full series on how to make commands!
BEST THING ABOUT THIS GUY IS HE DONT TAKE CREDIT ❤️
As soon as I close chrome my bot goes offline and when i go to replit to check it says your replit went offline and in uptime robot it says 502 bad gateway and the monitor is down I don't why any one can you help me?bot is alive until i keep those tabs online (replit and uptime robot)
Tysm! 😉
Thanks a lot
This inspired us to create our own Discord bot. Will create a video on it soon!!!
can anyone help me
replit doesn't allow to create .env files anymore ...what to do
@@rome6323 We created a video on replit's updated way of handling .env files:
czcams.com/video/MaZpKREcIog/video.html
Thank you so much
awesome tutorial
though my token doesn't have any question mark, it is writing invalid syntax token has '?'
is there a way to make my bot look at certain sites and send me notifications if for example a price dropped to a certain number?
what version of discord.js you work in this video ?
Where can I find all the keywords for discord, like .reply or .content?
Heyy, please could someone say if Repl.it has cycling like Heroku? (I am looking for a Free Tier host without cycling.)
How do I set the default node version in replit? I tried nvm but it doesnt work on replit apparently
env folders dont work the way they do in this video. it makes me make them a different way and idk how to make it work
How to create a bot like apkpure.com which copy apk of playstore and keep version on tgeir site like automation
Please make a "Code a Twitch Bot with JavaScript - Host for Free in the Cloud" version. :-)
If anyone having an issue when pasting the TOKEN or any other stuff, just use ctrl+v if you on Windows and then if that does not work then hold the windows button on your keyboard and v at the same time, If you using a mac then just hold command / cmd + v at the same time! Thanks !
channel will give u award soon............
.env has changed, we cant create a folder, now it has a place that i cant understand called enviroment but i'm really lost!
you is a good teacher
The zen quote part isn't working for me, it says "TypeError: Cannot read property 'q' of undefined". How do I fix this?
I love you all at freeCodeCamp. Please keep doing what you do!
Hey, I have a question. It says i cant create and .env file. what should i do?
theres a section for secrets/environmental variables
in that it shows 'key' and 'api'
in the key you can put TOKEN
and in the api you will put your token and save it
the rest is same
If you are not able to create a ".env" file. go to the lock icon in the left side of the screen and name the key TOKEN and put youre token in the value
Thanks :D
discord.js version 12 doesn't work on replit so i can't use this code with version 14
Me: **opens video**
"Hiiii!!!!"
Can we get a new series for this? A lot has changed with Discord.js in 3 years including Replit no longer being a free option, node.js going from v12 to v20, and DIscord.js going from v12 to v14 (complete overhaul). Thanks!
how can i do the creating web server for the bot part in C#?
How can I change language of the quote? e.g. French, Italian, Spanish ... Thanks
Do any of you know what the intent statement would be for line 2 of the code
When I try to reply with a message from the database, I get an error saying "Cannot send an empty message." I have that portion of the code directly pasted from the freecodecamp article, including the part where starterEncouragements is added to encouragements if its empty
37:59 you could have something like:
"The following encouragement has been deleted:
*(encouragement goes here)*
"
Thank you
The bot gets online but the commands don't work I did everything the way it asked me too and I did the new method amd setted it up for Discord.js v13 but it gets online but it the commands don't work
Hey i don't understand i have an problem it's saying you can't use .env files anymore what can i do?
Is this possible with netlify, express and vscode?
very good tip, but I think they fixed it because it didn't work, I tried to leave it running but after about 3 hours the replit dropped my bot. I believe they are identifying the uptimerobot.
Coming from C++, those arrow functions really scare me. What's the purpose of the ) after the }?
Hi, how to margin a table to bottom of a page in html 5?
Hello, your video was very nice. But I look for some special functions, like how to start an event, maybe automatically scheduled too.
The second is, how to read some HTML lines out of a browser site. Like there are incoming event codes for a game, i want to let the bot post it automatically into a discord channel
Ok so I did everything in the coding section but it gives me an error listed in red and I'm not sure wot I'm doing wrong
I kinda hot confused at the token part but idk wot to do
It keeps saying "syntaxError: missing ) after argument list"
unsure where i'm messing up but is unable to get bot to read my messages, unsure if this is because i gave bot admin or if this is a syntax error
this is outdated
i know i have a python pfp
but i know some js and this method is outdated
at the new Discord.Client
add intents like:
client = new Discord.Client({intents: ["GUILDS", "GUILD_MESSAGES"]})
and install node js v16 on replit
Is all of this up to date still? I'm gettin an error saying not compatible with your version of ...
at 15:00, I am running the code but it is giving me the following error
TypeError [ClientMissingIntents]: Valid intents must be provided for the Client.
at Client._validateOptions (/home/runner/A-Bot/node_modules/discord.js/src/client/Client.js:480:13)
at new Client (/home/runner/A-Bot/node_modules/discord.js/src/client/Client.js:78:10)
at Object. (/home/runner/A-Bot/index.js:2:16)
at Module._compile (node:internal/modules/cjs/loader:1105:14)
please anyone help :/