discordjs / guide

The official guide for discord.js, created and maintained by core members of its community.
https://discordjs.guide
MIT License
1.57k stars 2.31k forks source link

v14 Deploy Commands code not working #1532

Closed EdwardPeepoHands closed 11 months ago

EdwardPeepoHands commented 11 months ago

Describe the bug

Following the guide or just copy pasting the files from Github results in node error.

PS C:\Users\User\Desktop\discord-bot> node .\deploy-commands.js
node:internal/fs/utils:350
    throw err;
    ^

Error: ENOTDIR: not a directory, scandir 'C:\Users\User\Desktop\discord-bot\commands\ping.js'
    at Object.readdirSync (node:fs:1527:3)
    at Object.<anonymous> (C:\Users\User\Desktop\discord-bot\deploy-commands.js:14:26)
    at Module._compile (node:internal/modules/cjs/loader:1256:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
    at Module.load (node:internal/modules/cjs/loader:1119:32)
    at Module._load (node:internal/modules/cjs/loader:960:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
    at node:internal/main/run_main_module:23:47 {
  errno: -4052,
  syscall: 'scandir',
  code: 'ENOTDIR',
  path: 'C:\\Users\\User\\Desktop\\discord-bot\\commands\\ping.js'
}

Node.js v18.17.0 

Trying to fix that by just moving the commands folder into another folder (./commands/commands/ping.js) results in a different, more complex error:


Node.js v18.17.0

Started refreshing 3 application (/) commands.
DiscordAPIError[50035]: Invalid Form Body
guild_id[NUMBER_TYPE_COERCE]: Value "undefined" is not snowflake.
    at handleErrors (C:\Users\User\Desktop\discord-bot\node_modules\@discordjs\rest\dist\index.js:722:13)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async SequentialHandler.runRequest (C:\Users\User\Desktop\discord-bot\node_modules\@discordjs\rest\dist\index.js:1120:23)
    at async SequentialHandler.queueRequest (C:\Users\User\Desktop\discord-bot\node_modules\@discordjs\rest\dist\index.js:953:14)
    at async _REST.request (C:\Users\User\Desktop\discord-bot\node_modules\@discordjs\rest\dist\index.js:1266:22)
    at async C:\Users\User\Desktop\discord-bot\deploy-commands.js:36:16 {
  requestBody: { files: undefined, json: [ [Object], [Object], [Object] ] },
  rawError: {
    message: 'Invalid Form Body',
    code: 50035,
    errors: { guild_id: [Object] }
  },
  code: 50035,
  status: 400,
  method: 'PUT',
  url: 'https://discord.com/api/v10/applications/1181661979153285221/guilds/undefined/commands'
}``` 

### To Reproduce

Just  follow the tutorial or copy the files given at that point

### Screenshots

_No response_

### Device (please complete the following information)

Windows 11 on VSCode

### Additional notes

_No response_