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 Наука
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
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
very good tutorial :D
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 :)
Yea that's a good idea. I'll have to look into it.
Thank u bro
THANK YOU
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.
Can you make a video for the index and node_modules part of the folder aswell? This would be really helpful.
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?
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
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
@@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?
@@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
@@Reewen Okay, thank you so much. I have to say your channel is underrated.
how make batch file to activate existing virtual environment and then run our discord.py bot
that will be helpful, but how to make the other files
I thought writing only
"@echo
node."
will work.
But I had to write
"@echo
node index.js"
to make it work. But thanks regardless.
is that runs bot 7/24? or runs until we close the pc?
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
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
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?
@@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
@@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
I managed to fix it and the problem was I typed it incorrectly and that made my computer slow down
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.
In the task manager you just need to kill the node.js tasks
@@Reewen Thanks. I'm using a Windows server for once, and I really regret switching from Linux lol
shell:startup isnt working. what is the file path location
nvm i was missing startup folder in roaming
it still off when i turn off my laptop
Lol
Can you explain to us how to do this over the phone?
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
Wie ist es bei Linux Severn?
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
can you make a batch file for github?
you mean to pull from github?
can you make a batch file for Gradle?
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)
@@Reewen ok Thank You
when we put our pc on sleep mode does still the bot runs?
No, when you put your PC in sleep mode any programs running will halt
also how to close it when we want?@@Reewen
@@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
do u have an idea to do an another vbs file but that one closes the bot? please i really need it@@Reewen
@@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
i did everything correctly, but my bot wont go online
have you started your bot in an IDE or through the command line before?
the vps part didnt work
it's "vbs" not "vps"
But in case that's not the problem, what exactly doesn't work, with the "vbs" part
Bro, how can I stop the background run?
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
@@Reewen Thanks, you showed me on Discord!😄
@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
How do you end the bot??
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
@@Reewen thanks mate really helpful
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".🤗
how i can get my bot file
what do you mean
what folder you typing in how do you get this files
@@Reewen
@@ahmedMD984 try looking up a tutorial on how to create a discord bot.
This is not a video about how to set one up
Can you show us the index.js ?
why, what do you wanna know about my index.js file
@@Reewen It does not work with my index
@@mxasonwz Does the bot work when you start it normally through your development environment
@@Reewen yes
@@mxasonwz Is the index.js file the file you need to start to get the bot running