Code Your Own Discord Bot - Basic Command Handler (2021)
HTML-код
- Опубликовано: 17 окт 2024
- 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.visualstu...
Discord Developer Portal: discordapp.com...
Permissions Calculator: discordapi.com...
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 ruclips.net/video/8qIsRzV0Hpg/видео.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...
This is the only person that makes a Coding video actually enjoyable
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
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!
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
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
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?
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
*Checks description for pastebin*
*Screams internally*
ikr
same
had the same thing happen
its not hard
@@jankkhvej434 it is for us
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
This guy is legendary. He is recording this video at 3 AM
yo this man is a total genius, thanks man!
Everyone else:
I cried when my bot said pong!
Me:
Forgets the second m in command for 30 minutes
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
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.
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 ?????
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.
@@lucasli3273 and also who said i only watched tutorials? i was only questioning what he meant because he was speaking gibberish
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
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
Usually, I would just copy and paste, but I really want to learn that.
same mee to
same!!
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
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 ";"
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
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!
New video! Yeeeeeeeeeeeet
You are so helpful! Thanks so much! :D
Woah... I have been using the old discord.js code a while. Thank you for making this video!
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..
3:14 long time no comment - but the symbol you’re referencing is called the “pipe” operator 😎
'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 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.
I MADE MY BOT SAY :FLUSHED:
THANK YOU SO VERY MUCH FOR EXISTING!
lmao
YO @AlexEEZ
@@EfeIrmakk poggers
bro ily its the best channel for code education, its so helpfull
20 mins later bot corrupts and takes over the universe
the world: GET EMM!!!!!!
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.
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
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
Thank you so much for your tutorials. It helps me a bunch as a beginner!
Codelyon : u can do it like this or like this
Me : imma do whut u do aight!
Hi, good video. my bot is working but the commands arent and it doesnt show any error. how can i fix it?
Oh I fixed
@@TheWhiteMochoHOW
I felt like a master hacker when my bot said pong lol
why does it not say pong and i did everything right ?
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
Me when I type -ping : no response
also me watching this video 100 times : finds out i was missing the "!" in message
my code looking normal and I can make it online too but when I write -ping nothing happens can you help me?
Did you save
@@zombie7318 yes im sure
Mine doesn't work, I checked a million times and I dont see any mistakes in the code, its the same as yous but it doesnt work. I can get it to tell the lig that its online but it wont respond to my ping message. Any advice?
yeah same lol this tutorial was working literally 2 weeks ago lol(I watched all his videos and make a giant bot!)and it stopped working so it might be something on Discord's side but I'll keep you updated
@@cgw_yt did u find out?
@@rascal5731 nah sadly not, I've been researching mad hard too :(
thank you for the tutorials, they are really helpful and im having fun with the bot
XD "mason gay makeout club" sounds very mature
Bro, this video and its series are so helpful
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
You automatically earned my respect with that Desktop home screen. ✊
How can i do so the bot stays online always because when I close my command prompt it goes offline
I having a problem where my commands don’t want to execute, everything has been done correctly and my bot goes online etc. it just don’t execute the command when I do my prefix, anyone having the same problem or able to help me?
ok so if this cant help u idk but it helped me so it says (pong!);
} after the } scine put a ; symbol without anny space bar and open terminal in vs code and tipe node . this really helped hope i could help u :)
When i say Ping why do i dont get reply i did every step any help?
same. in my terminal it gives me errors
my bot is online But when i do !ping (! is my prefix) it doesnt work PLEASE HELP ME
Please do a tutorial on reaction roles because it is always down
thanks man! been having alot of troble lately, (because im just now getting into js)
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
me when i create a command to my bot:
h a c k e r m a n
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
i can't get is to say pong. ive tried everything that the comment section suggested, compared the code, but still no progress. been struggling on this for 3 days :( [im da beginner]
someone ples help!
Are you gonna do the music bot tutorial in this series too? Please do...
Thank you.
thank you so much for making those videos. This is helping so much!
I couldn't find the code in the description. I think you may have forgot to add it.
this isnt I give u source code! its you learn/do it yourself dont be a lazy bastard
@@Devtong hmm, yeah but im having a weird issue, while i typed everything right..just wanted to see what i did wrong.
@@Devtong same
Idk why, i dont get any error message but my bot doesn't respond to my command. Does anyone know why?
how do u make it so u can have spaces in the things ur saying
im trying to figure that out too hopefully you figured it out
@@biscuit6076 underscores for spaces
press the tab button in your keyboard
that should work
@@cope5223 doesnt work
@@chillisdepressed really? I did it on my computer and it worked
It is very important to keep spaces. This is the guideline for error code.
Finally, I done.
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
There a way to have the bot just read messages without a prefix?
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
so if i dont want any prefix do i leave blank in the place where we're supposed to put prefix?
5:27 saving my time
Bro I felt so proud when I created an actual bot that works, it felt like it was my child LMAOOO
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);
can sum1 help i did everything and spent 1 hour trying to see if i made a mistake and there is absolutely nothing diffrent and it still isnt responding when i do (prefix)ping
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?
@@leachosu in JS its Date.now();
Make sure u assign a variable to it
@@leachosu check ur discussion page on your channel. i sent a reply
dose this work on replit ??
BTW Love ur vids !!
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 think it isn't working, I did all the same but it doesn't reply... Please help
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!
when i say !ping it dont say back pong! hope you answer me
same
"mason gay makeout club"
my name is mason and I am here to ask "why tf are u in a vc called that lmfao"
i can't get my bot to say pong. Any solution?
Same my bot is also not responding
If I typed a command "-ping" for an example it would respond back with "pong!' around 2-5 times. Help.
sm here ;-;
Where it says powershell try deleting all of them and retrying node again. I think having too many of those build up causes that? I just delete them back to 1 and it always solved it so hoping that helps!
Shibu SS Yea, having to many powershells open does cause it, and for a longer fix restart visual, I did it 3 months ago and I’ve not have any problems since then
i got you... reset your token and replace the old with the new token
It's because you have a lot of terminals open.
Since nobody has made the bot ive been waiting for someone to make, ill just make it myself :)
1:18 dont mind me just marking where i left off for tomorrow me
Help me I did the same thing as u but when I do ?ping the not doesn't respond
my bot is not respoding!!!!!!!!!
These tutorials are great I subbed
where is the pastebin lol
lol
discordjs.guide tell me if its wrong link bc i dont remeber the link lol
"My bot says pong"
Me: YAAAA- wait, these tutorials never usually work, but this one did
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!')
so, the commands aren't working. whenever i try to do one the console says, "(node:3868) DeprecationWarning: The message event is deprecated. Use messageCreate instead
(Use `node --trace-deprecation ...` to show where the warning was created)" i tried doing the command it shows, but it just showed me the file location.
im havin the same problem too
@@abigailkaye9609 replace the message line with this: client.on('messageCreate', message =>{
they just updated node or smth thats why message is changed to messageCreate
@@hanly8610 thank youuuuu
I can't see where your typing
The bot isn't responding to my command. @CodeLyon, pls help me.
same HELP
i think you guys probably made mistake while typing the codes or didn't run the codes the way they were supported to go.
A maybe stupid question: Instead of a chain of Elseif, can I use Switch/Case?
ReferenceError: client is not defined guys, can you help me?
conseguiu resolver?
Try replace everything with this.
const Discord = require('discord.js');
const client = new Discord.Client();
const prefix = '-'
client.on("ready", () => {
console.log('Your bot is now online')
})
If anybody is having trouble getting the command to work make sure on
if(command === '-ping'){
message.channel.send('pong');
}
});
That you add the prefix inside the quotation or else it wont work (also if thats not working make sure you've added semi colons in all the right places)
Thank you!!!!
@@stromka5127 no problem happy i could help