我有一个用 TypeScript 编码的 Discord 机器人。如果需要,我正在尝试发出命令来终止其进程。当我尝试终止进程时,它不会被终止。我正在使用 ts-node-dev 来运行它。当我玩耍时,我看到 ts-node-dev 正在使用另一个可能被杀死的 PID。有什么方法可以过滤 PID,因为它的进程名称是 Node.exe,就像所有其他的一样。这是package.json
和stop.ts
包.json
{
"name": "kostegator",
"version": "1.0.0",
"description": "",
"main": "src/index.ts",
"scripts": {
"start": "ts-node-dev --respawn --transpile-only --poll ./src"
},
"keywords": [],
"author": "ProGamer2711",
"license": "ISC",
"devDependencies": {
"@types/ms": "^0.7.31",
"ts-node": "^10.1.0",
"ts-node-dev": "^1.1.8",
"typescript": "^4.3.5"
},
"dependencies": {
"canvas": "^2.6.1",
"discord.js": "^12.5.3",
"gif-encoder-2": "^1.0.5",
"mongoose": "^5.13.2",
"ms": "^2.1.3",
"node-fetch": "^2.6.1"
}
}
停止.ts
import { Command } from "../../Interfaces";
export const command: Command = {
name: "bstop",
description: "Stops the bot.",
usage: "bstop",
run: async (client, message, args) => {
if (message.author.id !== client.config.ownerId) return;
await message.channel.send("Stopping bot...");
client.destroy();
process.kill(process.pid);
},
};