Spaces:
Paused
Paused
Create index.js
Browse files
index.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
const { spawn } = require("child_process");
|
| 2 |
+
|
| 3 |
+
const botFiles = [
|
| 4 |
+
"spotify.js"
|
| 5 |
+
];
|
| 6 |
+
|
| 7 |
+
function startBot(file) {
|
| 8 |
+
console.log(`Starting bot: ${file}`);
|
| 9 |
+
const child = spawn("node", ["--trace-warnings", "--async-stack-traces", file], {
|
| 10 |
+
cwd: __dirname,
|
| 11 |
+
stdio: "inherit",
|
| 12 |
+
shell: true,
|
| 13 |
+
});
|
| 14 |
+
|
| 15 |
+
child.on("close", (codeExit) => {
|
| 16 |
+
console.log(`Bot process (${file}) exited with code: ${codeExit}`);
|
| 17 |
+
if (codeExit !== 0) {
|
| 18 |
+
setTimeout(() => startBot(file), 3000);
|
| 19 |
+
}
|
| 20 |
+
});
|
| 21 |
+
|
| 22 |
+
child.on("error", (error) => {
|
| 23 |
+
console.error(`An error occurred starting the bot (${file}): ${error}`);
|
| 24 |
+
});
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
botFiles.forEach(startBot);
|