Code Your Own Discord Bot - Event Handler & Command Handler V2 (2021)

Поделиться
HTML-код
  • Опубликовано: 17 окт 2024
  • Code your own Discord Bot! Event handlers and command handlers are the best way to organize your discord js bot. This will allow you to structure your code and provide a better and safer way to create a discord bot project. Code your own discord bot this way and you will see how useful these handlers can be. In the next following video, we are gonna start getting creative. Keep a lookout!
    ScreenBar Plus Links:
    BenQ Website: bit.ly/2ZIzWA3
    Amazon Link: www.amazon.com...
    Twitter: / usbenq
    _______________________________________
    🡺 Discord Server: / discord
    🡺 Twitch Channel: / itzalesh
    🡺 Second Chanel: / aleshgames
    🡺 Playlist: • Code Your Own Discord ...
    🡺 Twitter: / itzalesh
    NodeJS: nodejs.org/en/
    Visual Studio Code: code.visualstu...
    Discord Developer Portal: discordapp.com...
    Permissions Calculator: discordapi.com...

Комментарии • 713

  • @CodeLyon
    @CodeLyon  3 года назад +23

    Come join my discord server -> discord.gg/lyon

    • @BTWJrMo
      @BTWJrMo 3 года назад +7

      I got banned from it for saying "Ni||ceCa||rs"

    • @prodical3309
      @prodical3309 3 года назад +2

      LMAO

    • @Albino-cz2rd
      @Albino-cz2rd 3 года назад +1

      @@BTWJrMo LMAO well at least you've memed

    • @AcridDragoon
      @AcridDragoon 3 года назад +2

      ​ @CodeLyon the events dont work

    • @DataOS
      @DataOS 3 года назад

      @@AcridDragoon Join his discord and ask for help and they will help you. (And yes it still works)

  • @henic2611
    @henic2611 3 года назад +23

    For all those that struggle with adding a bot activity in the ready.js file listen!
    Caution at 11:15 you need to switch Discord and client around so the order is (null, client, Discord). In every other file it's always client and then Discord.
    This is the reason that your bot activity doesn't work when adding it to the ready.js file. If you look at the first line there (in the ready.js file) the order is client and then Discord and not the other way around as stated at 11:15.
    Took me a while to figure that out but other than that great video!

    • @squish162
      @squish162 3 года назад +2

      i trusted you on this and it ended up breaking my code lol

    • @giahuynguyen1914
      @giahuynguyen1914 2 года назад +1

      @@squish162 to fix it just go to message.js at line 3 *module.exports = (Discord, client, message) => {* change it to:
      *module.exports = (client, Discord, message) => {*

    • @mulhamalamry
      @mulhamalamry 2 года назад

      Thanks man i stayed hours looking for a solution and i didnt find liked and subbed (not an alt) for real

    • @youngsky6103
      @youngsky6103 2 года назад

      @@giahuynguyen1914 i dont have a message.js

    • @youngsky6103
      @youngsky6103 2 года назад

      @@giahuynguyen1914 cuz mine is saying codelyon is online even tho i dont have that set

  • @BigOrse
    @BigOrse 2 года назад +2

    Great tutorial, love your vids!! Just wanted to add if anyone's getting an error saying Dirs is not defined, change all 'Dirs' to 'Dir' and retry.

  • @TheOnlyZyn
    @TheOnlyZyn 3 года назад +88

    WE WANT MUSIC BOT PART 2!

    • @nyantix9980
      @nyantix9980 3 года назад +3

      YES WE DO!!!

    • @CodeLyon
      @CodeLyon  3 года назад +29

      Next week :)

    • @codingtise9187
      @codingtise9187 3 года назад

      @@CodeLyon Less gooooo
      BEST MUSIC BOT HERE I COME.

    • @acrestone
      @acrestone 3 года назад

      LETS GO!!!!!!!!!!!!!!

    • @chromus9149
      @chromus9149 3 года назад +5

      @@CodeLyon It never came out :(

  • @Mike-vu6oj
    @Mike-vu6oj 2 года назад +1

    for those of you getting the error saying bind is not a function, its because you have 1 or more files without module.export setup properly or have 1 or more empty files in the events folder

  • @darioakira6462
    @darioakira6462 2 года назад

    yo... i like ure teaching style! and also the VSC theme

  • @MagicBlue4444
    @MagicBlue4444 3 года назад +2

    That moment when you fix errors and it actually works and you feel so relieved...
    😎😎😎😎

  • @ahmad.software
    @ahmad.software 3 года назад +43

    We won't get the music part 2 ?

    • @CodeLyon
      @CodeLyon  3 года назад +12

      Next week :)

    • @Komamura
      @Komamura 3 года назад +1

      CodeLyon Can you do where it supports soundcloud as well ?

    • @zeMelvin2
      @zeMelvin2 3 года назад

      @@CodeLyon oooooh yay

    • @zeMelvin2
      @zeMelvin2 3 года назад +1

      @@CodeLyon can you make the music bot have a queue system, loop, skip, and play spotify songs? pls thanks!

  • @pansrb9862
    @pansrb9862 3 года назад +3

    why mine is not working, it says TypeError: Cannot read property 'forEach' of undefined

  • @tureisDK
    @tureisDK 3 года назад +3

    I have a question, my commands stopped working after this, I checked, but still couldn't find any mistakes. Please help!!! Could you please maybe leave a pastebin as a link of your code for me to double check, please!

    • @neltednaka
      @neltednaka 3 года назад

      the same happened to me

    • @giahuynguyen1914
      @giahuynguyen1914 2 года назад

      remove try and catch, if inside catch has console.log(error) then no

  • @ediperdin
    @ediperdin 3 года назад +1

    I love watching the time in the corner

  • @urbanevilfr
    @urbanevilfr 2 года назад +3

    when i try to type !ping it sais:
    TypeError: Cannot read properties of undefined (reading 'get')

  • @RapidzGamingHome
    @RapidzGamingHome 3 года назад +5

    I was getting the event.bind function error until I seen this comment from a user I can no longer find, It said to replace the "['command_handler', 'event_handler'] lines with this code instead
    var handlers = ['command_handler', 'event_handler']
    for(const handler of handlers){
    require(`./handlers/${handler}`)(client, Discord)

    • @Ericosia
      @Ericosia 2 года назад

      it still not working for me

  • @dcy9846
    @dcy9846 3 года назад +1

    my bot is not responding to any of the commands i put on discord, but i have all the code copied exactly. Can someone give me any clues as to why it isn't working?
    edit: this is my first time touching js ever so i have no clue how to debug this

  • @SpyTigro
    @SpyTigro 3 года назад +2

    I am getting an error from the event handler saying event.bind is not a function

  • @Spacey.
    @Spacey. 3 года назад +13

    I was literally working on my own command handler but im gonna use this because mine is very unoptimized
    PS: i watched your how to make a discord bot tutorial back in november and 2 days ago my bot got verified! So thanks.

    • @vapourizedh2080
      @vapourizedh2080 3 года назад +1

      congrats!

    • @thenono1
      @thenono1 3 года назад +1

      ahahah i watched it too around november but i'm not getting mine verified any time soon cuz i'm making it personalized for my server so i only have it there, but i'm planning on doing one that i hope will get on many servers so i can get it verified ^^

    • @giahuynguyen1914
      @giahuynguyen1914 2 года назад

      nice

  • @justk9947
    @justk9947 3 года назад +1

    Great video! Cant wait for music part 2 though xD

  • @fortnitebattelpass4133
    @fortnitebattelpass4133 3 года назад +29

    Hi, can you create a video on how to get a bot to write the status of how many servers the bot is on?
    please
    🙏🏽

    • @luigiboy72
      @luigiboy72 3 года назад

      or if you want the server count instead of member count use client.guilds.cache.size instead

    • @lakshyakumarsingh2215
      @lakshyakumarsingh2215 3 года назад

      @@senoryx thanks, it worked

    • @TERIHAX
      @TERIHAX 3 года назад +1

      for servers: message.channel.send(client.guilds.cache.size)

    • @legendaryemoji9848
      @legendaryemoji9848 3 года назад

      Guilds Count - client.guilds.cache.size
      Users Count - client.users.cache.size
      Channels Count - client.channels.cache.size
      Emojis Count - client.emojis.cache.size

    • @Secrethack_
      @Secrethack_ 3 года назад

      it is easy just type client.on("ready", () => {
      client.user.setPresence({ activity: { name: `>>help, Watching ${client.guilds.cache.size} servers!`}})
      })

  • @CloudyHi
    @CloudyHi 3 года назад +1

    everything works fine and i can even add more things to the handler thanks a lot!

  • @brodyghost5517
    @brodyghost5517 3 года назад +6

    How would you implement the code from the Member Counter video in this manager? I tried but i keep getting errors like 'membercounter is not a function'

    • @davmp4
      @davmp4 3 года назад

      bump

    • @gearmaxim
      @gearmaxim 3 года назад

      To do the member counter, change your ready.js script to...
      module.exports = (Discord, client, message) =>{
      const memberCounter = require('../../counters/member-counter');
      console.log('Tyrcnex Bot is online!');
      memberCounter(client);
      }

    • @gearmaxim
      @gearmaxim 3 года назад

      @@davmp4 To do the member counter, change your ready.js script to...
      module.exports = (Discord, client, message) =>{
      const memberCounter = require('../../counters/member-counter');
      console.log('Tyrcnex Bot is online!');
      memberCounter(client);
      }

  • @TlNYDlCK
    @TlNYDlCK 2 года назад +2

    To properly add something like the guildMemberAdd function, add the .js file with the same name to your guild folder.
    The code should look like:
    module.exports = (Discord, client, guildMember) => {
    let welcomeRole = guildMember.guild.roles.cache.find(role => role.name === 'member');
    guildMember.roles.add(welcomeRole)
    .then(client.channels.cache.find(channel => channel.name === 'general').send(`Welcome to our server.`));
    }
    It's important to notice that when we create the invite handler (ignoring the null input) we have two arguments (Discord and client). So our guildMemberAdd function must (!!) have those arguments in that order, plus the original variable of the old code when we just passed in guildMember. So in total 3 arguments.

  • @anon8723
    @anon8723 3 года назад +18

    Since NodeJS recently updated, old videos such as the Welcome message video does not work anymore. An updated tutorial or even a paste-bin fix would be lovely!!!

    • @liqinglin8936
      @liqinglin8936 3 года назад

      @CodeLyon pls do it

    • @refraynn
      @refraynn 3 года назад

      For me, it works fine. I have it set up in my Discord server.

    • @Ducxy
      @Ducxy 3 года назад

      Enable Intents

    • @VidTDM_XD
      @VidTDM_XD 3 года назад

      @@refraynn same

    • @liqinglin8936
      @liqinglin8936 3 года назад

      @@Ducxy how do you do that?

  • @Ace-lw8kh
    @Ace-lw8kh 3 года назад +2

    Happy New Year CodeLyon!!

    • @NinjaAhmed-cp3pe
      @NinjaAhmed-cp3pe 3 года назад

      WAIT!! YOU ACTUALLY COMMENTED IN DASHCRUFT video

    • @raze6861
      @raze6861 3 года назад

      @TK GamingHub Yoo Ubaid7

  • @BSPatel-sc6qq
    @BSPatel-sc6qq 3 года назад +8

    How to fix event.bind is not a function??

    • @damiangriffiths6740
      @damiangriffiths6740 3 года назад +1

      I also have this problem ):

    • @thxvzbtw.2398
      @thxvzbtw.2398 3 года назад +1

      I have the same problem, do you guys found the solution?

    • @damiangriffiths6740
      @damiangriffiths6740 3 года назад

      This is not really a solution, but I just kept deleting amd rewriting a whole bunch of code. event.bind is indeed a function so it is most likely that you have one tiny thing misspelled or written wrong. Also make sure to be running an event in the client folder when you start the bot for example the ready.js that he went over

  • @MCorange9
    @MCorange9 3 года назад +3

    this is for everyone thats having problems. make sure that the client, discord, message are in order. this took like a whole day to figure out....

  • @theredfede5617
    @theredfede5617 3 года назад +1

    Heya lyon! I started to create a new bot just a few weeks ago thx to ur channel, i love ur tutorials and u helped me a lot.
    Just one question, if i can ask: the command for the reaction roles stops working after 24h plus or less and i cant find the problem. I host the bot with heroku cause a my friend told about it. Any suggestions? Or at least something to make it resend the embed with the reactions every, dunno 10h? Or something like that.

    • @theredfede5617
      @theredfede5617 3 года назад

      Sry for eventually grammar errors, but i m italian and i kinda suck in english :/

    • @theredfede5617
      @theredfede5617 3 года назад

      Ok solved, its an heroku problem cause that host sucks, you just have to find another one

  • @agatra8795
    @agatra8795 3 года назад

    Once i do this will the commands from the previous tutorials begone?

  • @dextervanosch3495
    @dextervanosch3495 3 года назад +16

    @codeLyon, can u add the code link?

  • @wheeskii619
    @wheeskii619 2 года назад +3

    so i got an error from message.js saying _const command = client.commands.get(cmd)_ is undefined
    idk what i did wrong but _const command = message.client.commands.get(cmd);_ worked for me

    • @erio6812
      @erio6812 2 года назад +2

      Was banging my head on my desk for a good hour, you're doing gods work. Thank you.

    • @wheeskii619
      @wheeskii619 2 года назад +1

      @@erio6812also took me a while to find a fix, so i thought i should share it. glad i could help!

    • @lukasvarecha5887
      @lukasvarecha5887 2 года назад

      You are god ! I was so frustrated thank you so much.

  • @UniDoX
    @UniDoX 2 года назад

    Can you go trough your videos and do like #1 , #2 , #3 on the videos so people knows who to watch 1 after another?
    Anyways great tutorials.

  • @CHAOS_6E
    @CHAOS_6E 3 года назад +2

    Anyone else getting an error in the message.js file. The command.execute is somehow giving me problems.

  • @micaheberz6020
    @micaheberz6020 3 года назад +1

    These are *so* helpful man

  • @weebsmasher3911
    @weebsmasher3911 3 года назад +1

    This is wayyyy better than the old command handler, when I tried clearing the message it kept on saying pong, now it does everything fine. *It actually listens to me.*

  • @TheSilentknight.1
    @TheSilentknight.1 3 года назад +1

    can you help me, the get command in "message.js" not working well...
    (the terminal saying "Cannot read property 'get' of undefined")

    • @DeathlyBower959
      @DeathlyBower959 3 года назад +1

      Your variable order is wrong, make sure they match
      *HANDLERS*
      event_handler.js:
      module.exports = (client, Discord) => {
      //the code
      }
      coommand_handler.js
      module.exports = (client, Discord) => {
      //the code
      }
      *EVENTS*
      ready.js
      module.exports = async (client, Discord) => {
      console.log('Bot is online!')
      }
      message.js
      module.exports = async (client, Discord, message) => {
      //the code
      }
      index.js / main.js
      ['command_handler', 'event_handler'].forEach(handler => {
      require(`./handlers/${handler}`)(client, Discord);
      })
      If they are not in the right order, they pass in in the wrong variables

    • @aleksgolemanov9669
      @aleksgolemanov9669 2 года назад

      same

  • @synical4062
    @synical4062 3 года назад

    one problem. All commands work but if i do -play and type key word it wont play, only if it is url. any help?

  • @ud1n
    @ud1n 3 года назад +3

    this just broke all of my command. There are no error in the code, but all of my command doesn't work. Why is that ?

    • @freshness_of_air7909
      @freshness_of_air7909 3 года назад

      same

    • @DeathlyBower959
      @DeathlyBower959 3 года назад

      Not really sure if this will fix but here is a solution
      Maybe the variable order is wrong
      *HANDLERS*
      event_handler.js:
      module.exports = (client, Discord) => {
      //the code
      }
      coommand_handler.js
      module.exports = (client, Discord) => {
      //the code
      }
      *EVENTS*
      ready.js
      module.exports = async (client, Discord) => {
      console.log('Bot is online!')
      }
      message.js
      module.exports = async (client, Discord, message) => {
      //the code
      }
      index.js / main.js
      ['command_handler', 'event_handler'].forEach(handler => {
      require(`./handlers/${handler}`)(client, Discord);
      })
      If they are not in the right order, they pass in in the wrong variables

    • @ud1n
      @ud1n 3 года назад

      @@DeathlyBower959 wow thanks for the solution, I'll try to check it maybe. But I'll stick to the old one. It works just fine for me. Thanks for solution though 😊

    • @DeathlyBower959
      @DeathlyBower959 3 года назад

      @@ud1n np

  • @Th3_Ghost
    @Th3_Ghost 2 года назад +1

    when i try to run a comnand i get this error:
    const command = client.commands.get(cmd);
    Cannot read properties of undefined (reading 'get')

    • @jacobbarker8903
      @jacobbarker8903 2 года назад

      I'm getting the same error. Not sure what I'm missing

  • @MasterDude2000
    @MasterDude2000 3 года назад +13

    I think you should make a quiz command video. I did one and I think other people would like to know about it too :)

  • @FawryFx
    @FawryFx 3 года назад +2

    It doesn't work with my old code from your video tutorial for some reason. It keeps on saying something is undefined.

    • @jessekind1517
      @jessekind1517 3 года назад

      just means you made an error or typo

    • @DeathlyBower959
      @DeathlyBower959 3 года назад

      Not really sure if this will fix but here is a solution
      Maybe the variable order is wrong
      *HANDLERS*
      event_handler.js:
      module.exports = (client, Discord) => {
      //the code
      }
      coommand_handler.js
      module.exports = (client, Discord) => {
      //the code
      }
      *EVENTS*
      ready.js
      module.exports = async (client, Discord) => {
      console.log('Bot is online!')
      }
      message.js
      module.exports = async (client, Discord, message) => {
      //the code
      }
      index.js / main.js
      ['command_handler', 'event_handler'].forEach(handler => {
      require(`./handlers/${handler}`)(client, Discord);
      })
      If they are not in the right order, they pass in in the wrong variables

  • @lassevestergaard5813
    @lassevestergaard5813 3 года назад +1

    Very good video ;) / idea: Ticket command with Reaction!

  • @cracktus8534
    @cracktus8534 2 года назад +1

    I have an error where visual studio code keeps telling me MODULE_NOT_FOUND and keeps referencing the directory things you put in there like './handlers/${handler}'. I don't know what I've been doing wrong and I can't find any answers. I would very much appreciate help if someone else has found this too.

    • @izayusedwards9965
      @izayusedwards9965 8 месяцев назад

      i know this is a tad late but if your still stuck on this replace the ' with `

  • @galacticuniverse5355
    @galacticuniverse5355 3 года назад +1

    Thank you so much! This helped me a lot

  • @stcalo
    @stcalo 3 года назад +2

    You mentioned there is a way to not have to pass Discord into every file at 14:30. Do you mind giving me a link or something to where I can learn how to go about doing that? Thanks!

    • @Fallenuk8
      @Fallenuk8 3 года назад

      did u ever figure this our bro

    • @stcalo
      @stcalo 3 года назад

      @@Fallenuk8 I haven't yet, sorry

  • @cheshiresauce
    @cheshiresauce Год назад

    can someone help me? so the code has no errors and the bot runs properly and is shown online at discord, but it's not responding to any commands whatsoever.. I don't know what I'm doing wrong. I have also already given it the proper permissions to be able to send messages.

  • @TheThouZands
    @TheThouZands 3 года назад +7

    Thank you for reding the documentation in our behalf :)

  • @hunch3986
    @hunch3986 3 года назад +2

    Suggestion, fun bot commands, maybe like the random image one you did in 2019 or like a mimic command

    • @amikmia3036
      @amikmia3036 3 года назад

      yes really that is required

  • @GavinGoGaming
    @GavinGoGaming 3 года назад +2

    To re-add the "GuildMemberAdd" just go to main.js and add this code under the "['command_handler', 'event_handler'] part:
    edit the roleName variable to what your role name is
    client.on('guildMemberAdd', guildMember =>{
    const roleName = 'member';
    let welcomeRole = guildMember.guild.roles.cache.get(role => role.name(roleName))
    guildMember.roles.add(welcomeRole);
    });

  • @Aryan-ds3ks
    @Aryan-ds3ks 3 года назад +2

    i did the event handler but now none of the kick/ban/mute commands work even tho i put client in front of them :/

    • @puresheep5863
      @puresheep5863 3 года назад +2

      did you fix it? I don't even know what to do with my commands

    • @Aryan-ds3ks
      @Aryan-ds3ks 3 года назад

      @@puresheep5863 no dude in discord server noone helps either

    • @DeathlyBower959
      @DeathlyBower959 3 года назад

      Not really sure if this will fix but here is a solution
      Maybe the variable order is wrong
      *HANDLERS*
      event_handler.js:
      module.exports = (client, Discord) => {
      //the code
      }
      coommand_handler.js
      module.exports = (client, Discord) => {
      //the code
      }
      *EVENTS*
      ready.js
      module.exports = async (client, Discord) => {
      console.log('Bot is online!')
      }
      message.js
      module.exports = async (client, Discord, message) => {
      //the code
      }
      index.js / main.js
      ['command_handler', 'event_handler'].forEach(handler => {
      require(`./handlers/${handler}`)(client, Discord);
      })
      If they are not in the right order, they pass in in the wrong variables

  • @Lz4Lz
    @Lz4Lz 3 года назад +2

    Getting Error: Cannot find module ( name of my commands ) when i do node . any fix?

    • @zishanvhora3139
      @zishanvhora3139 3 года назад

      You might have messed up in naming the files. Check for any capitalisation error.
      Or check out the path you've listed out
      Imma gonna try it today anyway

  • @mrcrafter32
    @mrcrafter32 3 года назад

    The legend is back yayy

  • @jalen2706
    @jalen2706 3 года назад +2

    Your videos are amazing! How do you make the bot DM a user when they are banned/kicked with the reason? Keep up the great work!!

    • @hasan9.11
      @hasan9.11 3 года назад

      It will not work. Because when the user is not in a mutual server of bot it will not work due to discord privacy. If your bot is global than it will work

    • @jalen2706
      @jalen2706 3 года назад

      @@hasan9.11 no, you are wrong lmao, I figured this out a while ago

  • @apps0319
    @apps0319 3 года назад +4

    Yo amazing vide codelyon, pls continue the series

  • @alimlki8702
    @alimlki8702 3 года назад

    why im getting this error i checked the code 100000 times it is just the same as your codes!!!
    TypeError: require(...) is not a function
    at C:\Users\Ali\Desktop\discordbot\index.js:9:38
    at Array.forEach ()
    at Object. (C:\Users\Ali\Desktop\discordbot\index.js:8:38)
    the line is:
    ['command_handler', 'event_handler'].forEach(handler =>{
    require(`./handlers/${handler}`)(client, Discord);
    })
    i really dont understand why im getting this error

  • @jonathanfernandez550
    @jonathanfernandez550 3 года назад +2

    Good video.
    I have some problems implementing handlers and commands this way:
    I lose every reference and autocompletion functions that Visual Code provides because the file references are done on execution time and not staticly (thats how I understand it). So, is there anyway I can make it work and do not lose those funcionalities?

  • @jennywantsfood3585
    @jennywantsfood3585 3 года назад

    Im a bit confused. In the main file i had more than just "client.on('ready')". If you have something like "client.on('guildMemberAdd', async guildMember => ..." what code you need to add to the guild file in the events folder?

  • @waddleton_
    @waddleton_ 3 года назад +3

    i cannot get the guildMemberAdd to work with this... can anyone help me? i do not get any errors so i dont know where i did something wrong

    • @canmann4485
      @canmann4485 3 года назад

      Me too

    • @gearmaxim
      @gearmaxim 3 года назад

      @@canmann4485 To do the member counter, change your ready.js script to...
      module.exports = (Discord, client, message) =>{
      const memberCounter = require('../../counters/member-counter');
      console.log('Tyrcnex Bot is online!');
      memberCounter(client);
      }

  • @devinddst7467
    @devinddst7467 3 года назад +2

    Hmm, So I am wondering is there any other reason besides how clean it looks?, would it for example run faster? will it be able to handle more at once ?. or does this not change

    • @Yosexd
      @Yosexd 3 года назад

      it just make it cleaner.
      if you make it cleaner, you can work faster

    • @danielzidek8169
      @danielzidek8169 3 года назад

      It is easier to implement new functions

    • @karusea2821
      @karusea2821 3 года назад +2

      more efficient, less event listeners

  • @stonexfire8211
    @stonexfire8211 3 года назад +2

    i am getting something like 'TypeError: Cannot read property 'get' of undefined' can someone help me abt this?

    • @DeathlyBower959
      @DeathlyBower959 3 года назад

      in one of your files, you have the variable order wrong, make sure your variable orders line up
      **HANDLERS**
      event_handler.js:
      module.exports = (client, Discord) => {
      //the code
      }
      coommand_handler.js
      module.exports = (client, Discord) => {
      //the code
      }
      **EVENTS**
      ready.js
      module.exports = async (client, Discord) => {
      console.log('Bot is online!')
      }
      message.js
      module.exports = async (client, Discord, message) => {
      //the code
      }
      index.js / main.js
      ['command_handler', 'event_handler'].forEach(handler => {
      require(`./handlers/${handler}`)(client, Discord);
      })
      If they are not in the right order, they pass in in the wrong variables

    • @aleksgolemanov9669
      @aleksgolemanov9669 2 года назад

      same

  • @trazynthemany2011
    @trazynthemany2011 3 года назад +1

    How would I get the command handler to read subfolders? Also couldn't I put the handlers in the guild events folder?

  • @ScDangerBr
    @ScDangerBr 3 года назад +3

    I Keep On Getting This Error Can Someone Help Me Error: ENOENT: no such file or directory, scandir './events/client'

    • @blakejohnson7998
      @blakejohnson7998 3 года назад +2

      Thats happends for me too

    • @blakejohnson7998
      @blakejohnson7998 3 года назад +1

      @Squeaky Rubber Ducky Thats what I did.

    • @lukelarson9162
      @lukelarson9162 3 года назад

      @@blakejohnson7998 make sure events is not in handlers or any other subfolders

  • @jhemilisantos3702
    @jhemilisantos3702 2 года назад

    Amazing video. thank you so much!

  • @mrphilly
    @mrphilly 2 года назад

    please i need help. command handler doesn't works its just the erroe saying execute is undefined

  • @jussosa
    @jussosa 3 года назад +1

    Can i get a pastebin i have done it way too much time so is that pssible

  • @Sammy37
    @Sammy37 3 года назад

    The legend is back!!!

  • @blepbloop2908
    @blepbloop2908 2 года назад +1

    I have literally the same code but it says its missing intents, this doesn't work

    • @kittatro
      @kittatro 2 года назад

      Downgrade your discord.js to v13 or do some research

  • @vapourizedh2080
    @vapourizedh2080 3 года назад +4

    Suggestion: Could you do a video on these commands
    Custom status
    meme
    Auto anti swearing
    Help command
    Mute channels
    Auto-moderation
    Games like discord tic tac toe or snakes
    setting prefix
    Also happy new year Alesh, thank you for the videos

    • @cheyennehamilton5423
      @cheyennehamilton5423 3 года назад +1

      i know how to do the custom status
      client.once('ready', () => {
      client.user.setActivity(`whatever you want in here`, {type: 'PLAYING'}) // PLAYING, WATCHING, LISTENING, STREAMING
      console.log('your bot name is online!');
      memberCounter(client);
      });

    • @cheyennehamilton5423
      @cheyennehamilton5423 3 года назад +1

      you can do PLAYING, WATCHING, LISTENING, STREAMING in the place it says type so there you go

    • @vapourizedh2080
      @vapourizedh2080 3 года назад

      @@cheyennehamilton5423 Thank you! but where do I put it, cause it looks like it will be putted on main.js

    • @presenterhaven625
      @presenterhaven625 3 года назад

      Help you can do
      Message.author.send(‘test’) // will send to the users ~DM’s

    • @vapourizedh2080
      @vapourizedh2080 3 года назад

      @@presenterhaven625 Could you DM on Discord so I know how to do it

  • @MagicBlue4444
    @MagicBlue4444 3 года назад

    Quick Question. Where does the code for adding a role to a new member instantly go? You change it so it doesn't go anywhere now?

    • @ACKLL
      @ACKLL 3 года назад

      @Raheb thanks bro

    • @lukas4817
      @lukas4817 3 года назад

      @Raheb in germany we call people like you "Ehrenmann"!, i tried so solve this problem for my own in the last 2 hours an nothing worked!

  • @Gamingchannel-ri7ro
    @Gamingchannel-ri7ro 3 года назад +2

    now my bot doesnt do anything for some commands
    there are no errors too
    please help

    • @DeathlyBower959
      @DeathlyBower959 3 года назад

      Not really sure if this will fix but here is a solution
      Maybe the variable order is wrong
      *HANDLERS*
      event_handler.js:
      module.exports = (client, Discord) => {
      //the code
      }
      coommand_handler.js
      module.exports = (client, Discord) => {
      //the code
      }
      *EVENTS*
      ready.js
      module.exports = async (client, Discord) => {
      console.log('Bot is online!')
      }
      message.js
      module.exports = async (client, Discord, message) => {
      //the code
      }
      index.js / main.js
      ['command_handler', 'event_handler'].forEach(handler => {
      require(`./handlers/${handler}`)(client, Discord);
      })
      If they are not in the right order, they pass in in the wrong variables

  • @NakisS
    @NakisS 2 года назад

    I have problem on main.js it writes: client.commands = new Discord.Collection(); | ReferenceError: client is not defined what i can do to fix it ?

    • @jytyp
      @jytyp 2 года назад

      Define the client. before you create client.commands, above it you need to first declare the client, so: const client = new Discord.Client({intents: ["GUILDS", "GUILD_MESSAGES"]});

  • @hackx2fr
    @hackx2fr 2 года назад

    For All The People that struggled here is the ready.js file that works
    Link:pastebin.com/zaYPbduL

  • @adrianaerospace1866
    @adrianaerospace1866 3 года назад +1

    can we get the code pls as i got some errors and people in your server did not help

  • @sappyog
    @sappyog 3 года назад +3

    for(const file of event_files){
    ^
    ReferenceError: event_files is not defined
    at module.exports (C:\Users\**\Downloads\------------\handlers\event_handler.js:8:23)
    at C:\Users\Si\Downloads\SapBotBeta\index.js:10:37
    at Array.forEach ()
    at Object. (C:\Users\**\Downloads\------------\index.js:9:38)

  • @Ballissle
    @Ballissle 3 года назад

    Sorry can anyone help? When the prefix is sent in a channel, it does not run the command that was typed but no errors occur. What do I need to add?
    edit: I fixed it. I accidentally wrote a , instead of a . where I add the file.endswith

  • @idontuseanymore-f7s
    @idontuseanymore-f7s 2 года назад +1

    Hi, I have this error
    const command = client.commands.get(cmd);
    ^
    TypeError: Cannot read property 'get' of undefined

    • @Circlity
      @Circlity 2 года назад

      client.command.get(cmd)
      **you don't need the s in command**

    • @idontuseanymore-f7s
      @idontuseanymore-f7s 2 года назад

      @@Circlity Oh yeah sorry I never saw that comment, I managed to fix this.

  • @nik7805
    @nik7805 3 года назад

    got error:
    TypeError: require(...) is not a function
    at /home/runner/Polaroid/index.js:9:35
    at Array.forEach ()
    at /home/runner/Polaroid/index.js:8:37
    at Script.runInContext (vm.js:130:18)
    at Object. (/run_dir/interp.js:209:20)
    at Module._compile (internal/modules/cjs/loader.js:1137:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1157:10)
    at Module.load (internal/modules/cjs/loader.js:985:32)
    at Function.Module._load (internal/modules/cjs/loader.js:878:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)

  • @electrox3218
    @electrox3218 3 года назад +1

    where did you define 'dirs'??? it says that dirs is not defined!
    please answer fast!!!

    • @gdmercy6969
      @gdmercy6969 3 года назад

      So in const load_dir it’s = to dirs not dir I had to figure it out

    • @electrox3218
      @electrox3218 3 года назад

      ​@@gdmercy6969 i dont understand. I have a const load_dir = (dirs) and then a => but i dont understand wdym

    • @Circlity
      @Circlity 2 года назад

      it's dir not dirs

  • @yayer_27
    @yayer_27 3 года назад

    that just made my server.js drop from 680 lines to 120 thank you lmao

  • @zarcocrafter
    @zarcocrafter 3 года назад +1

    suggestion (maybe irrelevant, but i like it): how to group commands in categories

  • @liqinglin8936
    @liqinglin8936 3 года назад +10

    a lot of old references do not work after this, pls do a tutorial on how to fix it!

  • @noiseeeee
    @noiseeeee 3 года назад +2

    I replace the old command handler with this new one and now the embeds dont work.
    Error: "TypeError: Discord.MessageEmbed is not a constructor"
    I'm using discord.js v12 and the latest version of NodeJS. Idk what's the problem :/

    • @noiseeeee
      @noiseeeee 3 года назад

      @@chapel1337 i solved it, you need to write "const Discord = require('discord.js')" above the module.exports line

  • @funnystuff5188
    @funnystuff5188 3 года назад +1

    it doesnt work pls help i did everything but the bot won't respond

  • @MstrangerGaming
    @MstrangerGaming 2 года назад

    thank you so much for this code method, but after setting all this now my bot is replying more than one time. Please anyone help.

  • @senpairyujin
    @senpairyujin 3 года назад +4

    am i going crazy? why does client look like a file on your end not a folder? oh... i should've kept watching XD

  • @techexplorer3989
    @techexplorer3989 3 года назад +2

    Which theme do you use bro (of VS Code)

  • @TheRadish
    @TheRadish 2 года назад

    i have this error :
    PS C:\Users\svenn\OneDrive\cayo> node .
    Cayo's manager is online
    C:\Users\svenn\OneDrive\cayo\events\guild\message.js:3
    if (!message.content.startsWith(prefix) || message.author.bot) return;
    TypeError: Cannot read properties of undefined (reading 'startsWith')
    at module.exports (C:\Users\svenn\OneDrive\cayo\events\guild\message.js:3:29)

  • @nerfmyglock
    @nerfmyglock 3 года назад

    Followed everything in the video but still get
    TypeError: event.bind is not a function
    How would I fix this?

    • @abcdkrjdh
      @abcdkrjdh 3 года назад

      i just rewrote event_handler.js and it fixed somehow

  • @gutluckbro9802
    @gutluckbro9802 3 года назад +1

    There is a small error that I am not able to identify
    "TypeError: Cannot read property 'content' of undefined"
    how do I fix this?

    • @lorycave1292
      @lorycave1292 3 года назад +1

      Same here, but is recent. A month ago i didn't had this error

    • @gutluckbro9802
      @gutluckbro9802 2 года назад

      @@lorycave1292 do u still have the error?

    • @lorycave1292
      @lorycave1292 2 года назад +1

      @@gutluckbro9802 yes, i asked on the discord server and they helped me

    • @gutluckbro9802
      @gutluckbro9802 2 года назад

      @@lorycave1292 yeah same here, just got reminded of ur comment and I was curious if u still had the problem. Anyways good day!

    • @noanticheat9332
      @noanticheat9332 2 года назад

      @@gutluckbro9802 can you help me out?

  • @Flourish0x
    @Flourish0x 2 года назад

    What theme are you using???

  • @ReaIgms
    @ReaIgms 3 года назад +7

    warn system, suggestion & bug system, ticket system and perms

  • @hell.yeah-
    @hell.yeah- 3 года назад +1

    everytime i do node . it tells me ReferenceError: e is not defined

  • @StarAronjay
    @StarAronjay 2 года назад

    Where would I put the welcome and auto-role message for new members?

  • @karlbeats4026
    @karlbeats4026 3 года назад

    why is mine not working??? when I start running it it doesnt give any error it just doesnt run

  • @camckee316
    @camckee316 2 года назад

    great video but how would you send a message if user typed an incorrect command?

  • @krabstickle
    @krabstickle 3 года назад +6

    TypeError: Cannot read property 'get' of undefined

    • @_Vap
      @_Vap 2 года назад

      @@Armond777 in your message.js file, in module.exports = (Discord, client, message), change the order by switching client and Discord so it would look like this (client, Discord, message)

    • @iowa8260
      @iowa8260 2 года назад

      @@_Vap you're a lifesaver man, thank you!

    • @kittatro
      @kittatro 2 года назад

      @@_Vap I LOVE YOU I WAS STRUGGLING DOING CONSOLE LOGS TRYING TO UNDERSTAND WHY THE CLIENT WAS COMING OUT SO WEIRD THANK YOUUU

  • @webuser0o1
    @webuser0o1 3 года назад

    in what language is it better to write a bot? python or js

    • @Sevenri7742
      @Sevenri7742 2 года назад

      Depends on which one you can understand and do better

  • @carlghanem402
    @carlghanem402 3 года назад +1

    Can you post the code please? I really need it because i cannot find the issue i have

  • @itzgoku07
    @itzgoku07 3 года назад +1

    Thx for tutorial you are OP

  • @magic8636
    @magic8636 3 года назад +1

    how do u do that thing where he turned all his code grey

  • @DNMC_RXGE
    @DNMC_RXGE 3 года назад +1

    When I switched to this command handler, my bot stopped responding to my commands. Is there anything wrong with my code?

    • @itzgoku07
      @itzgoku07 3 года назад

      same here

    • @luigiboy72
      @luigiboy72 3 года назад

      do you get any errors?

    • @itzgoku07
      @itzgoku07 3 года назад +2

      @@luigiboy72 i fixed it :)

    • @wigglebot765
      @wigglebot765 3 года назад

      @@itzgoku07 How did you fix it? Mine still won't respond to any commands.

    • @itzgoku07
      @itzgoku07 3 года назад

      Have you installed ffmpeg and other packages

  • @bigtdm10mc69
    @bigtdm10mc69 3 года назад

    Awesome when are you going to finish your music series. I really need a music bot