Nodemon在discord.js上进行更改时不会重新启动

huangapple go评论59阅读模式
英文:

Nodemon doesn't restart when changes are made on discord.js

问题

我正在使用discord.js在JavaScript上制作一个Discord机器人。我正在使用nodemon运行它,但当我对脚本进行更改时,脚本不会重新启动。请帮助我!

  • index.js
const { Client, IntentsBitField } = require("discord.js");

const client = new Client({
  intents: [
    IntentsBitField.Flags.Guilds,
    IntentsBitField.Flags.GuildMembers,
    IntentsBitField.Flags.GuildMessages,
    IntentsBitField.Flags.MessageContent,
  ],
});

client.on('ready', (c) => {
    console.info(`✔ ${c.user.tag} is online.`);
});

client.on('messageCreate', (msg) => {
    if (msg.content == 'Hello!')
        msg.reply('Hi!');
});

client.login(
  "my key"
);

命令是nodemon src/index.js

日志如下:

[nodemon] 2.0.22
[nodemon] 若要随时重新启动,请输入 `rs`
[nodemon] 正在监视路径:*.*
[nodemon] 正在监视扩展名:js,mjs,json
[nodemon] 正在启动 `node src/index.js`
✔ [RR] Military Bot#1578 已上线。
[nodemon] 由于更改而重新启动...

我尝试将命令从nodemon src/index.js更改为nodemon -L src/index.js,但没有奏效。然后我尝试从终端运行而不是从package.json,但仍然没有效果。

英文:

I'm making a discord bot on JavaScript using discord.js. I am running it via nodemon, but when I'm making changes to the script, the script doesn't restart. Please help me!

  • index.js
const { Client, IntentsBitField } = require("discord.js");

const client = new Client({
  intents: [
    IntentsBitField.Flags.Guilds,
    IntentsBitField.Flags.GuildMembers,
    IntentsBitField.Flags.GuildMessages,
    IntentsBitField.Flags.MessageContent,
  ],
});

client.on('ready', (c) => {
    console.info(`✔ ${c.user.tag} is online.`);
});

client.on('messageCreate', (msg) => {
    if (msg.content == 'Hello!')
        msg.reply('Hi!');
});

client.login(
  "my key"
);

The command is nodemon src/index.js

The log is:

[nodemon] 2.0.22
[nodemon] to restart at any time, enter `rs`
[nodemon] watching path(s): *.*
[nodemon] watching extensions: js,mjs,json
[nodemon] starting `node src/index.js`
✔ [RR] Military Bot#1578 is online.
[nodemon] restarting due to changes...

I tried changing the command from nodemon src/index.js to nodemon -L src/index.js, but it didn't work. And then I tried running from the terminal instead of the package.json but again, nothing.

答案1

得分: 0

尝试执行

npm -g uninstall nodemon

然后

npm -g install nodemon

我找到的解决办法。

英文:

Try executing

npm -g uninstall nodemon

then

npm -g install nodemon

The fixed that I found.

huangapple
  • 本文由 发表于 2023年7月7日 02:46:57
  • 转载请务必保留本文链接:https://go.coder-hub.com/76631730.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定