Code Your Own Discord Bot - Basic Command Handler (2021)
Vložit
- čas přidán 25. 06. 2020
- Code your own Discord bot! Coding a basic command handler can be very easy when you try discord js. This video shows you how to create custom commands for your own discord bot using this basic method. I will be uploading the advance method tomorrow morning! Coding your own discord bot is very easy!
🡺 Discord Server: / discord
🡺 SECOND CHANNEL: / alesh
🡺 Twitch Channel: / itzalesh
🡺 Twitter: / itzalesh
NodeJS: nodejs.org/en/
Visual Studio Code: code.visualstudio.com/
Discord Developer Portal: discordapp.com/developers/
Permissions Calculator: discordapi.com/permissions.html - Věda a technologie
Come join my discord server -> discord.gg/lyon
Where is the pastebin?
@@faulzylmao lol
@CodeLyon Your este Coooooo
@@faulzylmao whatd he say
@codeLyon Pastebin, please?
me when I got my bot to say hi:
*p r o g r a m m e r*
Same Bro............SAME
LOL XD
XD
My bot goes offline when I close command prompt and visual studio code
How can I keep it online 24/7
@@unknown_1213 czcams.com/video/8qIsRzV0Hpg/video.html
i literally cried when my little bot guy said "pong!"
I hope I can feel it to . But my but doesn't start
asiful akib have you got the correct token?
asiful akib try changing the token
@@kyron7850 my bot has the right token. it comes online when i do node . but still it doesnt respond
i have the code exceacly the same
@@kyron7850 I ve change it once . I think I'll try again .
you know he is a coder if he is Coding at 3 AM lmao
lol i didnt notice that he is an epik programmer
@@_aage ikr
XD
mate you right
1:48am for me...
Me: gets an error
Also me: spends 3 hours to try to find out my error
Also Also me: cant spell message
Me too
bruh same
EXACTLY THE SAME
I SPELT MUSSAGE
hey ı cant get my bot online ' node . ' not working can u help me
same
xd
pc: error!
me: spends like an hour adjusting everything
me: inserts ; symbol at line 5
pc: everything works
That's javascript for you
Pretty irritating
I also forgot that.
one of apperently multiple errors thx mate xD
LOL SAME TO ME
This is the only person that makes a Coding video actually enjoyable
You were so helpful step by step and made it so easy and made it in parts so you can go in depth, I dropped a sub to your channel
yo this man is a total genius, thanks man!
Following this playlist. Can't wait for the next!
New video! Yeeeeeeeeeeeet
You are so helpful! Thanks so much! :D
I already did some of this, but........... this guy is awesome! I looked at his channel and is full of these things, which motivates me. I always wanted to have my own bot.
Woah... I have been using the old discord.js code a while. Thank you for making this video!
It would be cool if you included that this was part 2. It was very difficult finding this next part. But other than that, I feel so smart making it this far lol
Nice vid, Keep it up! Cant wait for more!
Thanks for the tutorial CodeLyon. I was having difficulties making it work until i realised i put a . where there was not meant to be one haha but i keep learning from your videos thank you so much.
bro ily its the best channel for code education, its so helpfull
Didn't look in your tutorials for a long time watched you when you had like 200 - 400 subs and you only had like 4 videos for bot tutorials I just wanted to thank you again for teaching me the basics meanwhile now I advanced to making bot commissions and bots from simple moderation bot to advanced highly customizable MEE6 lvl bot. I am rly happy you gained 12 k subs now keep up the great work ^^. and I like that you swapped to const command now and don't use switch(args[0]) anymore because that was so broken and had so many bugs but yeah I later learned to fix it too. Hope you reach 100k soon
This made me smile.
How do u put your bot offline?
@@gamingwitharoma9267 it'll go offline after a minute or 2
@@Asumji btw it says it has a problem with a const idk which one
the discord disconnect ping at 6:02 sent me on a search for who the heck I was on call with
me too XD
SAMEE i got scared for a sec
lol me to
i was singing and when i heard that I just shock,I have 500 people on server in my ming i just said bye guys deleting server rn lol
6:03 i heard
Thank you so much for your tutorials. It helps me a bunch as a beginner!
thank you for the tutorials, they are really helpful and im having fun with the bot
i have just started making my own discord bot using the 2019 tutorials and now your doing newer tutorials that are more updated my luck lol
edit: no way i go thrugh my gmail see someone replied and i got 50 likes most likes ive ever got on a comment
lol same
same, finally got it to run and now I look at this and I'm like bruh
its really like the same thing though
same here
HAHA same
*Checks description for pastebin*
*Screams internally*
ikr
same
had the same thing happen
its not hard
@@jankkhvej434 it is for us
Bro, this video and its series are so helpful
thank you so much for making those videos. This is helping so much!
I lowkey started crying when my bot responded
Im so proud of myself
same
good for you my bot wont even stay on now
Same bro lol now i got like 150working comms on the bot
Me: codes a whole 2d game, what ya' dog'doin
for the people who don't know how to open command prompt in visual studio code:
press Ctrl and ` at the same time. ( the ` key is the key on the top left corner just under Esc)
Tysm.
you are a genius omg thank!
This guy is legendary. He is recording this video at 3 AM
LOVE THIS SERIES
I’m reading all these comments, and I’ve been having the same problems, I’m new to coding with Discord Bot. It’s not always you’ve coding wrong, save your work shut it down, shut down discord, re open them, put your Bot online, and try that. That’s what I’ve literally been doing. Hope this helps!
YOU’RE A LIFE SAVER
DUDE TY
U HELPED SO MUCH
It didn’t help me or just said
Line 2
Char 1
Error syntax error
Code 800A03EA
Source Microsoft jscript compilation error
Tysm! take my like
do i have to turn my bot offline to update the data, or can i just do node . and have it update automatically
For everyone whose bots are online but the commands themselves aren't working (check for typos first ofc), aka the bot seems to just be ignoring them, check the bot permissions, they should have the permission to read/send messages, history etc. Experiment with different permissions, this is what made it work for me.
but i give it the admin permision
@@joeyderosas7009 Same.
can you send the script you did?
These tutorials are great I subbed
thanks man! been having alot of troble lately, (because im just now getting into js)
Please do a tutorial on reaction roles because it is always down
You automatically earned my respect with that Desktop home screen. ✊
Thanks for doing this videos man
Are you gonna do the music bot tutorial in this series too? Please do...
Thank you.
Usually, I would just copy and paste, but I really want to learn that.
same mee to
same!!
Everyone if you code it and then go to the CMD/command terminal and you type CD {your bot file name} and then type NODE . and it won’t show any errors or won’t say your bot is online I had that issue what worked for me was I refreshed the BOT TOKEN and pasted the new one in the bot login code and when I went to CMD to launch it it said my my bot was online and it was and codelyon big thanks to you I have now watched several of you discord bot tutorial videos!
Since nobody has made the bot ive been waiting for someone to make, ill just make it myself :)
Great tutorial! In the future you should think about a video about having the bot hosted 24/7 :)
i solved this issue with a vm :)
@@TheRealASN you can host it in the cloud so um bruh
Everyone else:
I cried when my bot said pong!
Me:
Forgets the second m in command for 30 minutes
thank you so much man you're AWESOME
It is very important to keep spaces. This is the guideline for error code.
Finally, I done.
how many of u thought while watching the video at 6:06 that if u were disconnected to a discord voice chat xD
me LOL
me too xd
me
6:02
How can i do so the bot stays online always because when I close my command prompt it goes offline
Tysm!
thank you very much man ;)
3:14 long time no comment - but the symbol you’re referencing is called the “pipe” operator 😎
yeah what if I want to make a same command and the bot send randomize line each being send?
btw great video, easy to follow
thanks it works!!
Awesome! Ty so much
I spent a week trying to figure out why tf he wasnt saying pong back and literally cried when I realized this whole time all I was missing was a ; at the end 😭😭
LOL YOU JUST SAVED ME A WEEK XD
A??
@@shevinn5877 a ";"
Really good tutorial 😁 I’d like to see a tutorial for reaction roles, so the bot can give the role that the server owner assigned to a reaction icon, for example:
1. The bot asks what message to assign a reaction to (by message I.D.)
2. The bot then asks for the emoji to put on the reaction (by emoji I.D.)
3. Finally the bot asks which role to assign to the reaction
(Sorry if that didn’t make sense, I can’t explain things too well 😂)
@@CanaryLivesOn dude he wants to make the command not invite a bot
@@epixerty ?????
@@hotsoda46 what do u want
You'll never learn to code if you only watch tutorials
@@lucasli3273 not like I've been coding since 2019 and know C#, JavaScript, and Lua, but I guess it's none of your business.
Thank you, you're a life saver
I'll try this tomorrow!
Can you make a music bot 2020 tutorial please? I started code from 2019 video bot not working so please make a new tutorial. Thank you!
i was going with the tutorial, and when i just wanna launch bot there was a error:
"TypeError: args.shift is not a function"
How to repair this?
its args.shift() , make sure u wrote that correctly
pastebin.com/8nRQjjJL here a pastebin file made by me. Refer to this if u face any errors
I don't quite understand what the purpose of splitting the code is, can anyone explain that to me? I addition, what would be the syntax if I wanted the bot to detect messages without the prefix?
thank you so much :D
'message' is now deprecated and you need to use 'messageCreate' from now on in 2022! so adjust this in the code from the video.
EDIT: Also make sure that you have your intents set correctly because now you need to explicitly define your intents for 2022 id look up a more recent tutorial
how do i adjust that in
thanks for including the pastebin i appreciate it ..........
wait where is it?
@@fadianihsan7834 he didnt include it.
i set my prefix to "fur" but when i test it out its not responding with pong at all, i checked if my code was the same as yours but it still wont work and yes i did try to save my code
Thanks!
Thanks for teaching me.
I MADE MY BOT SAY :FLUSHED:
THANK YOU SO VERY MUCH FOR EXISTING!
lmao
YO @AlexEEZ
@@EfeIrmakk poggers
my bot is not respoding!!!!!!!!!
So thankful for this easy tutorial!
thanks man
I have an issue that I haven't seen anyone tackle, if i use spaces for the commands i want to say/bot to say then they wont work, can anyone help me please? I'm desperate at this point
A litte late but I used visualizer's aid and it worked! Instead of the line provided, I used:
if (command === 'ping'){
const newLocal = 'Pong Pong Pong Pong';
message.channel.send(newLocal);
when you are watching 1.11 v videos but the code doesn't work and you finally realize codeLyon is back for the new version :D
I just update the gateway intents, no big deal.
How?
@@vemoryu1198 discordjs.guide/additional-info/changes-in-v12.html
@@vemoryu1198 there is a new serie for v12
the old one fir v11 and the code doesnt work anymore
Thanks a lot dude, You saved me from going on wrong direction haha
Thanks this helped
what should i do when i want my input commands with spaces?
my bot won't respond with pong! and when I run the node . it says: Segmentation fault: 11 Can someone help me
try node index.js or node main.js
I just wanna tell you guys, that I did have problems setting it up at first. Nothing works out immediately once you follow a tutorial, you have to experiment a bit, try out a new way to do the thing you're trying to do. Like how I first followed the 2019 tutorial then the 2020 one. And I had some trouble with getting the discord version show up at first, I had to manually check it and fill it in. Aaand how when I try to run it in the program it doesn't work, but in cmd it does! I had to think of ways to get through these problems first. And to my surprise, it worked perfectly after that! I also found out how to make the bot say the command user's username and tag.
Don't be afraid to experiment, always experiment. :D
yes but everything i try doesnt do anything
@@epiccturtle well think about it a bit
what could correlate to/resolve this issue I'm having
and try to do it a different way
try new things that the tutorial doesn't tell you about maybe
of course, it not working at all is also a possible case, if so, I can't really help you with it..
For the commands like "-ping" does it have to be in lowercase or can I capitalise the first letter?
nvm works ty
When i say Ping why do i dont get reply i did every step any help?
same. in my terminal it gives me errors
So, I'm trying to make a bot that sends messages at specific times, how can I do that?
you need to grab date time from console and post message if the time constant you want your bot wants to post at matches the current date time
@@steveschaninger2535 and how can i grab date time from console?
@@leachosu3428 in JS its Date.now();
Make sure u assign a variable to it
@@leachosu3428 check ur discussion page on your channel. i sent a reply
thank you, you are amazing
And people say you need school to do this
the bot doesnt start for me anymore as it just says a syntax error code
line: 1
char: 1
error: synrax error
code: 800A03EA
source: microsoft jscript compilation error
I can't see where your typing
In case anyone was having trouble with adding a second command, and gets the error Unexpected token ')' make sure you added the ending bracket '}' after the second line
Where
hi, so i've started coding a bot for a discord server im in, and I made a basic command. But i changed what I wanted the bot to say, and now when i type the command it doesn't send anything. I've attempted to reset the code and do it again, but still havent gotten any results?
im having trouble with the else if line of code and im not sure whats wrong with it
20 mins later bot corrupts and takes over the universe
the world: GET EMM!!!!!!
Wouldn't it be better to use a switch statement if you have many commands?
I have a problem I have done evrything right and typed the code again checked it 5-10 times and the -ping doesnt work im tryng to fix it for an hour and I cant do it can someone please help.
5:27 saving my time
I tried to make a command where you type !good bot and then it reacts. To do that I tried using
else if(command == 'good bot')
for it, but it appears the bot just doesn't recognize this. It doesnt give an error message in visual studio either. If i use
else if(command == 'goodbot')
it does react as it should.
Is there an easy way to do this or not. I tried to google it, but this is my first experience with javascript, so I don't really get what they say.
Already thanks if someone has an answer!
edit: I solved it by adding
const args2 = message.content.slice(prefix.length).split();
const command2 = args2.shift().toLowerCase();
and using
else if(command2 == 'good bot')
instead. It boils down to just using something that's not a space as argument in split( )
tysm
Thank you, spent way too long trying to figure out what was wrong with my code
why does it not say pong and i did everything right ?
wow!! new subscriber here
XD "mason gay makeout club" sounds very mature
The bot isn’t responding after when ran the command.
Do you mind helping me out??? I think that the 2019 method works a little better. @CodeLyon
yeah true same
same
i got it but i went to the advanced and something went wrong so i started from scratch
For me its a problem with the 'const command' not being used or something, I don't know why it's doing that ;-;
remove /+/ and add Empty and save it and run again
whenever i type "?ping" (question mark is my prefix) it says the prefix is not defined. what do I do?
so if i dont want any prefix do i leave blank in the place where we're supposed to put prefix?
You never left the code in the description like you said you would
yeah noticed that too lol
Bruh just type it
here this is the code from mine. it is the excest as in the video.
const Discord = require('discord.js');
const client = new Discord.Client();
const prefix = '-';
client.once('ready', () => {
console.log('your bot name is online!');
});
client.on('message', message =>{
if(!message.content.startsWith(prefix) || message.author.bot) return;
const args = message.content.slice(prefix.length).split(/ +/);
const command = args.shift().toLowerCase();
if(command === 'ping'){
message.channel.send('pong!');
}
});
client.login('your discord bot token');
@@vonckjenl3633 what a lad
yeah
I felt like a master hacker when my bot said pong lol
i have only 1 question, i have to open command prompt and start the bot every time i want the bot to be online and do what i want?
your videos are really easy to understand, i wanted to make a bot that deletes all the commands written on only 1 text channel, and it works perfect !
Idk why, i dont get any error message but my bot doesn't respond to my command. Does anyone know why?
How do I change the pong command so that when it replys it says
🏓 | Pong! That took 198ms
or however many ms it took.
Change
('pong')
to
('🏓 | Pong!')
it should look like this:
if(command === 'ping')
message.channel.send('🏓 | Pong!')