终止在discord.js中运行的子进程



我正在试图杀死/访问一个进程。它应该启动另一个机器人,也能够杀死它。这是我所做的。

const { Client,  Intents, DiscordAPIError } = require("discord.js");
const client = new Client({
intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES, Intents.FLAGS.GUILD_MEMBERS]
});
const fs = require('fs');
const Discord = require (`discord.js`)
const child = require (`child_process`)
module.exports = {
name: `start`,
description: `start the bot`,
execute(message, args){
child.exec(`node test.js`, (stderr, stdout) => {
message.channel.send(`stderr: ${stderr}, stdout: ${stdout}`)
})

}
}

这是我想要停止bot的命令。

const { Client,  Intents, DiscordAPIError } = require("discord.js");
const client = new Client({
intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES, Intents.FLAGS.GUILD_MEMBERS]
});
const fs = require('fs');
const Discord = require (`discord.js`)
const child = require (`child_process`)
module.exports = {
name: `stop`,
description: `stop the bot`,
execute(message, args){
//no idea what to put here
})



}
}

我可以得到进程id或保存在一个变量访问进程的东西吗?谢谢你的帮助;)

这将终止您的程序

process.exit()

addprocess.exit()

这样的

const {
Client,
Intents,
DiscordAPIError
} = require("discord.js");
const client = new Client({
intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES, Intents.FLAGS.GUILD_MEMBERS]
});
const fs = require('fs');
const Discord = require(`discord.js`)
const child = require(`child_process`)
module.exports = {
name: `stop`,
description: `stop the bot`,
execute(message, args) {
process.exit()
})
}
}

最新更新