Discord | How to automatically start your discord Bot with a batch file (discord.js/discord.py)

Поделиться
HTML-код
  • Опубликовано: 27 июл 2024
  • In this tutorial I'll show you how to automatically start your discord bot when you boot your computer with a batch (bat) file
    This should work with both bots programmed in java script (discord.js) and python (discord.py). There is only a difference of one line in the batch file.
    My help Discord: / discord
    Text Tutorial:
    CREATION OF THE STARTER BATCH
    1. Go to the location where the files of your discord bot are located
    2. Create a text dokument (you can do that with notepad)
    3. For discord.js type in this (so if you programmed in java script):
    @echo
    node .
    3.For discord.py type in this (so if you programmed in python):
    @echo
    python YOURBOT.py
    4. Press save as. There you can call this what you want. Just make sure that you add .bat at the end to save it as a bat file. Your file could look something like this "start.bat".
    (If you don't want the terminal to be invisible skip the next steps (till you are at the autostart part) and double click your batch file to start the bot)
    CREATION OF THE VBS FILE TO MAKE OUR BOT RUN IN THE BACKGROUND
    5. Create another text document. In this one put in the following commands:
    Set WshShell = CreateObject("WScript.Shell")
    WshShell.Run chr(34) & "TheFilePathToYourBatFileYouCreated" & Chr(34), 0
    Set WshShell = Nothing
    6. Press save as. Call it what you want but make sure you add ".vbs" at the end of the name to make it a vbs file (if you want the bot to start now jsut double click the file. There will be no prompt coming up if you have done it right)
    AUTOSTART:
    7. Press Windows + R
    8. Type in the run window that will appear: "shell:startup"
    9. This will open a folder. Right click in the folder, hover with your mouse over the new button and then select new shortcut
    10. Put in the filepath to your .vbs file. It could look similar to this: A:\1 Archieve\5 Programmier Stuff\Discord-Bots\AutoRole\background.vbs
    After you created your shortcut, you are done. Now every time you start/restart your pc the bot will start as well
    Timestamps:
    0:00 - Intro
    0:49 - create the starting batch file
    1:55 - create the vbs file (to run the bot in the background)
    4:20 - making the bot automatically start with windows
    Music:
    Track 1: dj quads - it’s near
    RUclips link: • dj quads - it’s near
  • НаукаНаука

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

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

    Postscript:
    Make sure you type the code in the vbs file correctly. Typos can result in problems with your pc as long as the file is running

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

    Dude, thank you so much. this solved so many performance things for me. especially because I don't need to have vsc open 24/7 now

  • @aħa
    @aħa 3 года назад +1

    very good tutorial :D

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

    nice video dude :) You are also active in the Comment Section, good job! I saw a lot of people asked how to stop the background file, maybe (I have no clue how this works) you can make a file that can stop the vbs file. But thx for the good tutorial :)

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

      Yea that's a good idea. I'll have to look into it.

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

    Thank u bro

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

    THANK YOU

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

    Can you use same thing for Discord Bot Maker files, to start? My discord bot maker is crashing sometimes, and i think that running it from Batch is more secure.

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

    Can you make a video for the index and node_modules part of the folder aswell? This would be really helpful.

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

      The node modules folder is just where the discord API and some other libraries for the bot is in. And index js is the bot. What should I make a video about with those?

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

    OK WHY THE HELL DOES THIS ONLY HAVE 2K VIEWS. IT SHOULD HAVE 1 MILLION TYSM
    and how would I restart it when I update the code. Im discord.js

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

      You will need to close the process in the task manager.
      There should be one or more processes called Node server side script or something similar to that. Just end those tasks and the botnis shut down. To start it again just run the vbs file again and the bot starts.
      As far as I know you can also make an event in the bots program code that let's you restart it

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

      @@Reewen is there a way to make it like when the bot goes offline it auto runs the vbs file so the bot is continuously on. So that when I update its code. I can run the restart command which will exit the process and it auto runs the vbs again?

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

      @@celsiuss You can do that yes. You can let the bot always send out an online signal and let another program read that signal. When that signal goes down you can let the program start the vbs file. That's at least how I would go on about this.
      How exactly you can realize that is something you will need to figure out yourself though since I haven't done that

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

      @@Reewen Okay, thank you so much. I have to say your channel is underrated.

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

    how make batch file to activate existing virtual environment and then run our discord.py bot

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

    that will be helpful, but how to make the other files

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

    I thought writing only
    "@echo
    node."
    will work.
    But I had to write
    "@echo
    node index.js"
    to make it work. But thanks regardless.

  • @FaresFakhouri
    @FaresFakhouri Год назад +1

    is that runs bot 7/24? or runs until we close the pc?

    • @Reewen
      @Reewen  Год назад +1

      it only runs as long as your PC is on.
      If you want it to run 24/7 you need to host the bot from a PC/server that runs 24/7

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

    This has destroyed my computer as when I started it it said background.vbs did something and has completely buggered my pc up. My cursor stopped working two of my monitors stopped working and every time it said there was an error it said it was from a file called background.vbs please if you know how to fix this explain

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

      This is really weird. I mean you can check the code of the file there should be nothing in there causing this.
      But you can fix this by booting into save mode and deleting the shortcut from your startupfolder
      Could you tell me what exact error occures?

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

      @@Reewen when I start up my pc it doesn’t allow me to move my cursor and just pops up a message telling me that something has gone wrong with the file. It makes my pc very glitchy and turns off my monitor. I think I might have typed some code in wrong and it has made the startup of my pc boot it wrong

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

      @@JFSdragonfire Yea it must be a typo or something similar. It's just a simple visual basic script that creates a shell so I don't see what else could cause an issue like this. Well anyway let me know if you can find the exact issue so I can warn other viewers not to make the same mistake

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

      I managed to fix it and the problem was I typed it incorrectly and that made my computer slow down

  • @cmd.toddwick
    @cmd.toddwick Год назад

    But how do you find and terminate the vbs? I dont want to stop it from auto-starting, I just want to take the bot offline for a second, without having to restart my server.

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

      In the task manager you just need to kill the node.js tasks

    • @cmd.toddwick
      @cmd.toddwick Год назад

      @@Reewen Thanks. I'm using a Windows server for once, and I really regret switching from Linux lol

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

    shell:startup isnt working. what is the file path location

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

      nvm i was missing startup folder in roaming

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

    it still off when i turn off my laptop

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

    Can you explain to us how to do this over the phone?

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

      There is an answer in this reddit thread: www.reddit.com/r/Discord_Bots/comments/a30rck/hosting_discord_bot_from_android/
      I am not going to make a video about this though, hope that link helps

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

    Wie ist es bei Linux Severn?

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

      The part with the batch file should still be the same (just with the linux equivalent of a batch file) for running it in the background I think if you start your program via the command line and add a & at the end it may run in the background

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

    can you make a batch file for github?

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

      you mean to pull from github?

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

    can you make a batch file for Gradle?

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

      I am afraid I don't know what Gradle is but a batch file is essentially just a file that runs a command in the command line. So just put in the command that you need to input in cmd for your thing to run in a text file and save it as a batch file (add "@echo" in the beginning of the text file as well to make sure)

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

      @@Reewen ok Thank You

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

    when we put our pc on sleep mode does still the bot runs?

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

      No, when you put your PC in sleep mode any programs running will halt

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

      also how to close it when we want?@@Reewen

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

      @@FaresFakhouri you can do it via the task manager by stopping the nodejs processes, if youw ant to do it differently you will have to modify the vbs file

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

      do u have an idea to do an another vbs file but that one closes the bot? please i really need it@@Reewen

    • @Reewen
      @Reewen  8 месяцев назад +1

      @@FaresFakhouri sorry you will have to do it by yourself. I haven't worked on shell scripts for a while and I don't have time to look into it

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

    i did everything correctly, but my bot wont go online

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

      have you started your bot in an IDE or through the command line before?

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

    the vps part didnt work

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

      it's "vbs" not "vps"
      But in case that's not the problem, what exactly doesn't work, with the "vbs" part

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

    Bro, how can I stop the background run?

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

      You can stop the bot by opening the task manager and closing the tasks that are called Node.js: Server-side JavaScript (if you programmed in javascript)
      If you want to have a windows open simpli run the batch file and a terminal windows will open. Closing that window will shut down the bot

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

      @@Reewen Thanks, you showed me on Discord!😄

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

      @principal Cookie It should be called something like python.exe . As far as I know all python programs will show up as python.exe in the taskmanager so it'll be a little hard to find the bot if you got several python programs running.
      And when it comes to troubleshooting it's quiet possible that there is something with the vbs file. A typo somewhere in there could already break the file.
      What you can try is just running the batch file and see if the bot runs then. If it does you will know that there is something with the vbs file

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

    How do you end the bot??

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

      If you did exactly as I did, the Taskmanager is the best way. The Bot will not be called the way you called your bot, there will be a few tasks called something along the line of node if you did it in java script and something along the line of python if you programmed it in python
      EDIT: If you made your bot in js there should be 3 tasks called Node.js: Server-side JavaScript just ending those tasks should render your bot offline

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

      @@Reewen thanks mate really helpful

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

      To stop the script from running in the background, you need to end the task who is running the script. In your case (the task who is running the script from video) you need to end the task called "Node.js: Server-side JavaScript".🤗

  • @ahmedMD984
    @ahmedMD984 11 месяцев назад

    how i can get my bot file

    • @Reewen
      @Reewen  11 месяцев назад

      what do you mean

    • @ahmedMD984
      @ahmedMD984 10 месяцев назад

      what folder you typing in how do you get this files
      @@Reewen

    • @Reewen
      @Reewen  10 месяцев назад

      @@ahmedMD984 try looking up a tutorial on how to create a discord bot.
      This is not a video about how to set one up

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

    Can you show us the index.js ?

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

      why, what do you wanna know about my index.js file

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

      @@Reewen It does not work with my index

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

      @@mxasonwz Does the bot work when you start it normally through your development environment

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

      @@Reewen yes

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

      @@mxasonwz Is the index.js file the file you need to start to get the bot running