我在试图杀死/访问一个进程。它应该启动另一个机器人,同时也能杀死它。这就是我所做的。
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}`)
})
}
}这是我想要阻止机器人的命令。
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或在变量中保存一些东西来访问进程吗?(谢谢你的帮助;)
发布于 2022-05-01 18:58:00
这将终止您的程序。
process.exit()发布于 2022-10-27 19:43:22
添加process.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()
})
}
}https://stackoverflow.com/questions/72079540
复制相似问题