[TRAIN WHISTLE]
Hello.
OK, I have to admit something to you.
This is a substitute train whistle.
But this is not a substitute Coding Train video.
I'm so excited about what I am embarking
on today, a new tutorial sequence about how
to make your own Discord bot.
I hope that by the end of all these videos, however many
I end up making, you'll be able to have
your own bot up and running in your own Discord server,
or a server that you participate in.
Now, if you haven't already joined
the Coding Train Discord, [TRAIN WHISTLE] oh dear,
I'm so sorry.
If we could get the sound effect of the actual train whistle.
[TRAIN WHISTLE]
Please come and join.
I'll put an invite to the Coding Train Discord server
in the video's description.
If you don't have a Discord account,
you're going to need to sign up for one.
But guess what, you'll need one to make your own Discord bot.
Please, the first thing you should do is go to read me,
where there is a code of conduct and a set
of rules and expectations for the server.
And in order to get access to all of the channels,
you'll need to react with an emoji
to acknowledge that you have read this message
and agree to follow the code of conduct.
So there's lots more to say about the Coding Train
community on the Discord server itself.
It's a great place if you need help with your code,
if you just want to hang out and share pictures of your pets.
There's a lot of channels for a lot of different things.
And so please come and say hi there.
One of my favorite things to do is
to read the Introductions channel,
because I get to know the community of people who
are watching these videos and where they come from
and what they care about and what they're excited to try
and make themselves with code.
OK, enough, enough.
In this first video, what I want to do
is cover all of the technical pieces, like what do you need?
You need a text editor, you need a console, you need Node.js.
What are all the pieces you need to run your Discord bot?
And in case you haven't heard of one of those pieces,
where can you find the resources to get those up
and running on your computer?
As well as how to create a Discord application
through the developer docs, or the developer website,
the Discord developer website.
And get your secret token key thingies
that you'll need to be able to run your Discord bot, OK?
So we're going to do that, all that, in this first video,
and then I'll start following up with the basics of writing
the code, and showing you how to run the bot,
and all that other good stuff too.
All right, what are the pieces of the puzzle here?
Ultimately, where I want to get to first
is that on my own computer, I am going
to be typing code into a text editor.
The text editor I use is VSCode, Visual Studio Code,
but you could really use any.
I want to run this code.
Maybe this is going to be a file called index.js.
And I want to run this code using Node.js.
So I'm going to say something like node index.js.
And when I run this, the bot itself
is running on my laptop, my personal computer.
But how is it going to communicate with Discord?
Well, weirdly enough, Discord is also running on my computer.
So do they talk to each other directly like that?
Like am I running a bot on my computer
that's talking to Discord running on my computer?
No.
So discord is a service.
I'm just running the Discord client
on my laptop where I can send my messages
and read messages coming in.
But ultimately, there is a server,
the Discord server itself, that my laptop
is communicating with.
That's how, when I type a message,
it sends it to the server.
And presumably, somebody else who's
running-- if it's direct message to somebody else,
then that message I send to the server is going to get
sent to that other client.
So this server is managing everything.
So ultimately, actually, the way that I
will see a message that the bot posts
or that I could send a message from Discord to the bot--
this should really be a much bigger diagram.
Now that I've zoomed in a little bit,
if my code wants to send a message
to be viewable in Discord, it's going to send it to the server.
And the server will send it to the Discord client.
So ultimately, the bot that I'm writing
is a Discord application like the client.
It's just not as sophisticated.
It's just a command line thing that I
run through Node that can send messages and read messages.
Now, this isn't the end of the story.
I mean, running index.js as the Discord bot on my laptop
isn't a sustainable solution, because eventually I
need to close my laptop.
I need to put it away to go on vacation.
I need to sleep.
And I need a permanent computer that can always
have the Discord bot running.
And so what I would like to show you, eventually also,
is how to not run index.js on my local laptop here,
but to deploy it somewhere into the so-called cloud.
I could use a service like Glitch or Heroku
or DigitalOcean, or Amazon Web Services.
I could make my own Raspberry Pi or set up
my own old computer that's always
connected to the internet.
Anything that's like an always on computer
that can run my Node code can act as the permanent bot.
Now I can make this smaller again.
And the idea here is all the human beings,
as represented by these laptops, are communicating
with the Discord server.
They're sending messages.
They're receiving messages.
And now I have a new non-human being, a bot,
also communicating with the server,
sending and receiving messages.
And I can code and program any crazy ID
I want for how the humans and the bot
could interact with each other.
One thing that should really explain here.
I'm conflating the idea of the Discord service, which
is a company that runs probably a lot of different servers
that allows people to sign up for Discord accounts,
and the idea of a Discord server like the Coding Train Choo Choo
server.
So the terms Discord server generally
means like a server, a specific server for a single community,
like Coding Train, or there's an ML5 Discord,
and there's countless other Discord
servers for gaming communities and podcast communities.
And so all of those are like little bubbles in here.
And the clients that are members of Coding Train
are all connected to just one.
And I'm going to add my bot specifically to the Coding
Train Discord server.
But a bot, just like any human being,
can be members of multiple servers.
So really, this bubble here represents the discords service
itself, which is also a server that's
managing multiple instances of different communities
with their own servers.
I probably, in the end, have made this much more complicated
than it needs to be.
If I were to just simplify all this for a second,
there is a Coding Train community
that is a Discord server.
You can sign up and be a part of that community,
and read and write messages yourself.
And now I'm showing you how to sign up, essentially,
a bot, or robot, member of that community that can automate
different processes, reading, sending messages, reacting
to emojis, posting gifts, all sorts of other kinds of things
that a Discord bot can do.
So what do you need in order to be
able to make your own Discord bot?
Now certainly, there are lots of different ways
to make Discord bots, I'm sure.
But if you want to make one in JavaScript and using Node.js,
the things you will need are as follows.
Console access to your computer.
Another word for that is like terminal access.
I use iTerm.
There's Terminal on the Mac.
There's Powershell, Git BASH.
I'm always making this list over and over again on Windows.
I have a whole separate video about terminal and shell access
that you could watch if that's a totally new concept to you.
You need a text editor.
That's to edit your code.
I've already mentioned the one that I'm
going to use is VSCode.
Finally, you need to install Node.js.
And I have a whole video about what is Node
and how to install it and all that thing.
But really, you can just go to a URL
that I'll put in the video's description,
click the Download button, install it on your computer,
and you'll know it's working is if when you go into Terminal,
if you type in Node dash dash version,
you'll see a message come out that says,
I'm Node version something, instead
of, I don't know what Node is, help!
Let me show you all these things in action.
So this is my console.
I'm open to the console.
I'm using iTerm as my terminal application on the Mac.
I can put links to download that.
And again, there are countless other ones
that you could use on Mac, Windows, Linux, et cetera.
I'm going to type Node dash dash version.
Now, if I were to misspell that, or if you
didn't have Node installed, I would see something
like command not found, nope.
And I'm using something called ZSH.
Oh, my goodness, so many terms, so much weird stuff.
Again, I cover that more in my full console video
that you can take a look.
But hopefully, if you've gone to the Node website,
you've downloaded--
it doesn't really matter what version, to be honest.
I would grab what it says recommended for most users.
You've installed it on your computer.
You're back in your terminal window.
And you type Node dash dash version.
If you see it recognize it and give you a version number back,
you are good to go.
That said, you're struggling with this,
ask your question in the comments,
or come and join the Coding Train Discord itself,
and we'll help you get to this stage right here.
The next thing you want to do is go
to the Discord website itself and sign up
for a Discord account.
If you already have a Discord account, you can use that one.
You could make a new dummy account just
to test with your bot.
But I'm using my main Discord account,
because I can make multiple bots and try different experiments
through one Discord account itself.
So if you have Terminal and you're able to type Node,
if you have a Discord account, you
are ready to move on to the next video.
So in the next video, I'm going to show you
the Discord Developer portal, where you create
the actual bot account itself.
And that's where the information that you'll
bring into your code will live.
So that's coming up.
I can't wait.
I mean, I'm going to do it right now.
Maybe you will too.
I don't know, you'll--
take a break, take a break, take a break, relax.
Deep breath, deep breath, deep breath.
I'll see you for the next video, maybe, maybe, we'll see.
It's fine if you don't go.
I get it.
I'll just stop talking now.
Goodbye.
Bye.
[BLOWS KISS]
[MUSIC PLAYING]