Code a Discord Bot with JavaScript - Host for Free in the Cloud

Sdílet
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

Komentáře • 702

  • @freecodecamp
    @freecodecamp  Před 2 lety +95

    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

  • @asce313
    @asce313 Před 3 lety +110

    Stranger: which school are u from?
    Me: FreeCodeCamp

    • @playmovies8209
      @playmovies8209 Před 3 lety

      Oooo

    • @Saidur07
      @Saidur07 Před 3 lety +3

      W3SCHOOLS 🤤

    • @asce313
      @asce313 Před 3 lety +2

      @@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 😀👍

    • @Saidur07
      @Saidur07 Před 3 lety +5

      @@asce313 yeah true......
      I was kidding 🤐

    • @shraddhaagarwal9012
      @shraddhaagarwal9012 Před 3 lety +1

      @@Saidur07 g.

  • @Z1g0l
    @Z1g0l Před 3 lety +5

    I've been looking for that yesterday and boom! My favourite code learning channel delivers.
    You guys are amazing!

  • @FirenTGX
    @FirenTGX Před 3 lety +63

    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!*

    • @aaronfrazier8530
      @aaronfrazier8530 Před rokem +1

      facts lol we just need the paper and we will learn from here

  • @landsfadern2
    @landsfadern2 Před 3 lety +15

    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

  • @Hendika
    @Hendika Před 3 lety +28

    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

  • @uhmmm2110
    @uhmmm2110 Před 3 lety +218

    We want more beau stuff, he is an awesome teacher!

  • @nirbhayparmar
    @nirbhayparmar Před 3 lety +18

    What a high level of energy he has so much needed in this type of enthusiasm in our professors.

  • @SouProds
    @SouProds Před 2 lety +1

    tysm man, I've been looking for a tutorial everywhere, this was the most helpful one!

  • @simonbusshart1463
    @simonbusshart1463 Před 2 lety

    The style of explanation is incredible! Its like he speaks the Code... never seen this before. Everything makes sense perfectly. Thanks a lot

  • @Ritika-Das
    @Ritika-Das Před 3 lety +5

    Was really waiting for a video like this!

    • @lamb8086
      @lamb8086 Před 3 lety +1

      Yeah we know already...

  • @parikshitchavan5274
    @parikshitchavan5274 Před 2 lety +11

    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.

  • @aerofanceo1624
    @aerofanceo1624 Před rokem

    I have succesfully completed my bot using this tutorial 2 months ago. Thank you!

  • @enzoerfe8429
    @enzoerfe8429 Před 2 lety

    Really awesome and straight to the point! Looking forward to learning more from you

  • @xfelien3888
    @xfelien3888 Před 2 lety +1

    Thanks, the 24/7 hosting actually works. Thank you!

  • @manzourabdalla2279
    @manzourabdalla2279 Před 3 lety

    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

  • @0utono
    @0utono Před 3 lety +12

    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

  • @kevincarvalhodejesus4473
    @kevincarvalhodejesus4473 Před 2 lety +1

    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.

  • @kumasany
    @kumasany Před 3 lety +8

    34:46 click on the auto-format icon available at the left side of the console tab to format code.

  • @strikinganimeshorts5623
    @strikinganimeshorts5623 Před rokem +6

    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)

  • @deadlycopter
    @deadlycopter Před 2 lety +1

    This was a great tutorial! Thank you so much!!

  • @charlesmarchand9098
    @charlesmarchand9098 Před 3 lety +1

    Thank you!!! I learned so much of the syntax I feel like I can do anythinng

  • @amazingdestroy
    @amazingdestroy Před 3 lety +29

    I thought I recognized your voice! You're the guy in the hint videos

    • @cynapse993
      @cynapse993 Před 3 lety +2

      What hint videos?

    • @amazingdestroy
      @amazingdestroy Před 3 lety +2

      @@cynapse993 on the freecodecamp website. In the coding practice exercises

    • @pepparody
      @pepparody Před 3 lety +1

      @@amazingdestroy yes, he is the founder lol

  • @BiP00
    @BiP00 Před 3 lety +4

    Someone deaf and blind disliked the video unintentionally, he wanted to like it as well...

  • @xend_er6975
    @xend_er6975 Před 3 lety +42

    I already know this video is gonna be perfect for me 😂

  • @xi_red4936
    @xi_red4936 Před 3 lety +18

    Never have I ever been so early, and damn, a discord bot? Wow lol

  • @techcet5879
    @techcet5879 Před 3 lety +4

    This is the video i was waiting for

  • @areeb5160
    @areeb5160 Před 2 lety +4

    I recommend you guys to use a command handler as its much easier to sort out commands

  • @marcelnunez1658
    @marcelnunez1658 Před rokem

    I'm glad this channel exists.

  • @beastxgamer7168
    @beastxgamer7168 Před 2 lety +8

    When I press run, in the console unexpected token comes and the bot doesn’t come online

  • @guest9580
    @guest9580 Před 2 lety +8

    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 '?'

    • @velvet2712
      @velvet2712 Před 2 lety

      @@str.1337 How to change the version to 12.5.3?

  • @urfavouriteboi8905
    @urfavouriteboi8905 Před 3 lety +23

    When He Said "Coding A Bot With Python" i went BRUH

  • @3dninja54
    @3dninja54 Před 3 lety +2

    I claimed the free 3 month hacker plan, thanks FCC!

  • @freshy1862
    @freshy1862 Před 3 lety

    Awesome video thank you very much. Would love to show you my work some day

  • @returnZeroo
    @returnZeroo Před 2 lety

    That uptime robot trick was slick :)

  • @PastEquation922
    @PastEquation922 Před 2 lety +24

    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

  • @computerscience1099
    @computerscience1099 Před 3 lety +1

    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

  • @clashgamers4072
    @clashgamers4072 Před 3 lety +9

    Every thing was fine in this video except your light theme

  • @cynapse993
    @cynapse993 Před 3 lety +11

    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

  • @javier-fy9cl
    @javier-fy9cl Před 2 lety

    Thank you so much !!!

  • @koushiksarkar8808
    @koushiksarkar8808 Před 3 lety

    Great tutorial sir... very helpful...

  • @3dninja54
    @3dninja54 Před 3 lety +3

    I already know how to make an discord bot in JS, but I love being able to see Beau!

    • @rome6323
      @rome6323 Před 3 lety +1

      can anyone help me
      replit doesn't allow to create .env files anymore ...what to do

    • @GPeti07
      @GPeti07 Před 3 lety +1

      @@rome6323 On the left side menu click to the padlock 🔒 icon

    • @DeepakSharma-ug3ij
      @DeepakSharma-ug3ij Před 2 lety

      @@GPeti07 hi

  • @bobblehat9891
    @bobblehat9891 Před 2 lety +1

    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

  • @manaphygames
    @manaphygames Před 3 lety +3

    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

  • @parthmongia3220
    @parthmongia3220 Před 3 lety

    You are Great Sir and channel and very good for us .

  • @data8923
    @data8923 Před rokem +1

    just completed the bot thanks for the tutorial

  • @serenaclairetalks
    @serenaclairetalks Před 3 lety

    Thank you!

  • @jonathangerard745
    @jonathangerard745 Před 3 lety +1

    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?

  • @CodeWithTomi
    @CodeWithTomi Před 3 lety +4

    This is a great video!

  • @besthobbit
    @besthobbit Před 5 měsíci

    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.

  • @thevolatiledude6537
    @thevolatiledude6537 Před 2 lety +1

    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?

  • @micheller4631
    @micheller4631 Před 3 lety

    Idk who this guy is but I wish he was like my 2nd dad or something this was fantastic.

  • @viberiouss
    @viberiouss Před 2 lety +3

    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.

    • @MateusFerreira-on3kp
      @MateusFerreira-on3kp Před 2 lety

      aka a Grave accent

    • @caleab3280
      @caleab3280 Před 2 lety +1

      God bless

    • @DeepakSharma-ug3ij
      @DeepakSharma-ug3ij Před 2 lety

      this was helpme......thnx

    • @andrew3606
      @andrew3606 Před 2 lety

      Lol thanks this guy isn't really explaining he's just speaking

    • @reubenmenezes1139
      @reubenmenezes1139 Před 2 lety

      @@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.

  • @quackmeansquack
    @quackmeansquack Před 2 lety +1

    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?

  • @atosef7038
    @atosef7038 Před 3 lety

    Amazing !!

  • @BeauCarnes
    @BeauCarnes Před 2 lety +32

    Maybe next I should make it so those robots in the background in the intro can talk on Discord.

    • @alwaysgaveyouup1348
      @alwaysgaveyouup1348 Před 2 lety

      yeeeeeeeeeeeeeeeeeeeeeee boiiiiiiiiiiiiiiiiiiiiii

    • @justmrin
      @justmrin Před 2 lety

      yes please

    • @HitsDev
      @HitsDev Před 2 lety +3

      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.

    • @areeb5160
      @areeb5160 Před 2 lety +2

      Can you make a series on how to make a discord.js bot, so like moderation commands, economy commands etc.

    • @HitsDev
      @HitsDev Před 2 lety +1

      @@areeb5160 YESSS Please create videos or full series on how to make commands!

  • @madaraDgoat
    @madaraDgoat Před 2 lety

    BEST THING ABOUT THIS GUY IS HE DONT TAKE CREDIT ❤️

  • @loneWolf-sp7qc
    @loneWolf-sp7qc Před 3 lety +1

    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)

  • @ektarungta7442
    @ektarungta7442 Před 3 lety +2

    Tysm! 😉

  • @W1L7dev
    @W1L7dev Před 3 lety +1

    Thanks a lot

  • @programmercouple
    @programmercouple Před 3 lety

    This inspired us to create our own Discord bot. Will create a video on it soon!!!

    • @rome6323
      @rome6323 Před 3 lety +1

      can anyone help me
      replit doesn't allow to create .env files anymore ...what to do

    • @programmercouple
      @programmercouple Před 3 lety

      @@rome6323 We created a video on replit's updated way of handling .env files:
      czcams.com/video/MaZpKREcIog/video.html

  • @Human69420
    @Human69420 Před 2 lety

    Thank you so much

  • @kunalprashant
    @kunalprashant Před 3 lety

    awesome tutorial

  • @johnbarack1346
    @johnbarack1346 Před 2 lety +1

    though my token doesn't have any question mark, it is writing invalid syntax token has '?'

  • @evo3s75
    @evo3s75 Před 2 lety

    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?

  • @Saifgmr_
    @Saifgmr_ Před rokem +1

    what version of discord.js you work in this video ?

  • @magicianwizard4294
    @magicianwizard4294 Před 2 lety +1

    Where can I find all the keywords for discord, like .reply or .content?

  • @nikhilaggarwal6533
    @nikhilaggarwal6533 Před 2 lety +1

    Heyy, please could someone say if Repl.it has cycling like Heroku? (I am looking for a Free Tier host without cycling.)

  • @deductivefan01
    @deductivefan01 Před 2 lety

    How do I set the default node version in replit? I tried nvm but it doesnt work on replit apparently

  • @spangothers6962
    @spangothers6962 Před 2 lety +1

    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

  • @AyushPanditofficial
    @AyushPanditofficial Před 3 lety +1

    How to create a bot like apkpure.com which copy apk of playstore and keep version on tgeir site like automation

  • @hiltyMG
    @hiltyMG Před 3 lety +2

    Please make a "Code a Twitch Bot with JavaScript - Host for Free in the Cloud" version. :-)

  • @zuberkariye2299
    @zuberkariye2299 Před 3 lety

    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 !

  • @blackhole1431
    @blackhole1431 Před 2 lety +1

    .env has changed, we cant create a folder, now it has a place that i cant understand called enviroment but i'm really lost!

  • @programingwithali869
    @programingwithali869 Před 2 lety

    you is a good teacher

  • @aditi8889
    @aditi8889 Před 3 lety

    The zen quote part isn't working for me, it says "TypeError: Cannot read property 'q' of undefined". How do I fix this?

  • @ltnlabs
    @ltnlabs Před rokem

    I love you all at freeCodeCamp. Please keep doing what you do!

  • @nfnclan8223
    @nfnclan8223 Před 3 lety +5

    Hey, I have a question. It says i cant create and .env file. what should i do?

    • @div_07
      @div_07 Před 3 lety +3

      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

  • @falingunit
    @falingunit Před 2 lety +1

    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

  • @oussamael7304
    @oussamael7304 Před 10 měsíci +1

    discord.js version 12 doesn't work on replit so i can't use this code with version 14

  • @musdevfrog
    @musdevfrog Před 3 lety +4

    Me: **opens video**
    "Hiiii!!!!"

  • @MagentaRV
    @MagentaRV Před měsícem +1

    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!

  • @M1idget
    @M1idget Před 2 lety

    how can i do the creating web server for the bot part in C#?

  • @Codxut
    @Codxut Před 3 lety

    How can I change language of the quote? e.g. French, Italian, Spanish ... Thanks

  • @MattH-uj9op
    @MattH-uj9op Před rokem

    Do any of you know what the intent statement would be for line 2 of the code

  • @user-py8kj5ve4y
    @user-py8kj5ve4y Před 9 měsíci

    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

  • @sephstar-offical
    @sephstar-offical Před 2 lety

    37:59 you could have something like:
    "The following encouragement has been deleted:
    *(encouragement goes here)*
    "

  • @AbhishekSingh-mh6gp
    @AbhishekSingh-mh6gp Před 3 lety

    Thank you

  • @PlainSaga
    @PlainSaga Před 2 lety +1

    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

  • @artifice6818
    @artifice6818 Před 3 lety

    Hey i don't understand i have an problem it's saying you can't use .env files anymore what can i do?

  • @adriancamacho8703
    @adriancamacho8703 Před 2 lety

    Is this possible with netlify, express and vscode?

  • @tedesco182
    @tedesco182 Před 2 lety +2

    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.

  • @-TheBugLord
    @-TheBugLord Před 2 lety

    Coming from C++, those arrow functions really scare me. What's the purpose of the ) after the }?

  • @martinvlk4302
    @martinvlk4302 Před 3 lety

    Hi, how to margin a table to bottom of a page in html 5?

  • @tassezer0854
    @tassezer0854 Před rokem

    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

  • @Dakotah137
    @Dakotah137 Před 2 lety

    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"

  • @lunareclipsis3915
    @lunareclipsis3915 Před rokem

    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

  • @helgin_lol
    @helgin_lol Před 2 lety +4

    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

  • @mrd.j.2303
    @mrd.j.2303 Před 2 lety

    Is all of this up to date still? I'm gettin an error saying not compatible with your version of ...

  • @kinda_history_nerd
    @kinda_history_nerd Před rokem +2

    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 :/