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

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

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

问题

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

  • index.js
  1. const { Client, IntentsBitField } = require("discord.js");
  2. const client = new Client({
  3. intents: [
  4. IntentsBitField.Flags.Guilds,
  5. IntentsBitField.Flags.GuildMembers,
  6. IntentsBitField.Flags.GuildMessages,
  7. IntentsBitField.Flags.MessageContent,
  8. ],
  9. });
  10. client.on('ready', (c) => {
  11. console.info(`✔ ${c.user.tag} is online.`);
  12. });
  13. client.on('messageCreate', (msg) => {
  14. if (msg.content == 'Hello!')
  15. msg.reply('Hi!');
  16. });
  17. client.login(
  18. "my key"
  19. );

命令是nodemon src/index.js

日志如下:

  1. [nodemon] 2.0.22
  2. [nodemon] 若要随时重新启动,请输入 `rs`
  3. [nodemon] 正在监视路径:*.*
  4. [nodemon] 正在监视扩展名:js,mjs,json
  5. [nodemon] 正在启动 `node src/index.js`
  6. [RR] Military Bot#1578 已上线。
  7. [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
  1. const { Client, IntentsBitField } = require("discord.js");
  2. const client = new Client({
  3. intents: [
  4. IntentsBitField.Flags.Guilds,
  5. IntentsBitField.Flags.GuildMembers,
  6. IntentsBitField.Flags.GuildMessages,
  7. IntentsBitField.Flags.MessageContent,
  8. ],
  9. });
  10. client.on('ready', (c) => {
  11. console.info(`✔ ${c.user.tag} is online.`);
  12. });
  13. client.on('messageCreate', (msg) => {
  14. if (msg.content == 'Hello!')
  15. msg.reply('Hi!');
  16. });
  17. client.login(
  18. "my key"
  19. );

The command is nodemon src/index.js

The log is:

  1. [nodemon] 2.0.22
  2. [nodemon] to restart at any time, enter `rs`
  3. [nodemon] watching path(s): *.*
  4. [nodemon] watching extensions: js,mjs,json
  5. [nodemon] starting `node src/index.js`
  6. [RR] Military Bot#1578 is online.
  7. [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

尝试执行

  1. npm -g uninstall nodemon

然后

  1. npm -g install nodemon

我找到的解决办法。

英文:

Try executing

  1. npm -g uninstall nodemon

then

  1. 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:

确定