Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

119
Visualizações
Can't deploy my slash commands Discord.js
  • EDIT: turns out i was still on node 16.4.4 and this was the issue, slash commands require node 16.6 or higher. This happened because i switched machines and had my node_modules folder added to the git i was using.

Running my guild.commands.js or deploy-commands.js yields this error:

node:internal/modules/cjs/loader:936
  throw err;
  ^

Error: Cannot find module '../common'
Require stack:
- C:\Users\Thomas\Documents\discordBot\node_modules\discord-api-types\payloads\v9\index.js
- C:\Users\Thomas\Documents\discordBot\node_modules\discord-api-types\v9.js
- C:\Users\Thomas\Documents\discordBot\deploy-commands.js
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
    at Function.Module._load (node:internal/modules/cjs/loader:778:27)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Module._compile (node:internal/modules/cjs/loader:1103:14)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    'C:\\Users\\Thomas\\Documents\\discordBot\\node_modules\\discord-api-types\\payloads\\v9\\index.js',
    'C:\\Users\\Thomas\\Documents\\discordBot\\node_modules\\discord-api-types\\v9.js',
  ]
}

I have set the scope to application.commands and bot and i have given the bot all the permissions. My first slash command is working properly but i simply cannot add new ones. I have tried node 16.4 and 17.4 and tried reinstalling everything from node to discord.js. It is always the same error with the common module. I am following this tutorial: https://discordjs.guide/creating-your-bot/command-handling.html#individual-command-files

this is deploy-commands.js:

const fs = require('fs');
const { REST } = require('@discordjs/rest');
const { Routes } = require('discord-api-types/v9');
const { clientId, guildId, token } = require('./config.json');
const rest = new REST({ version: '9' }).setToken(token);

const commands = [];
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));

for (const file of commandFiles) {
    const command = require(`./commands/${file}`);
    commands.push(command.data.toJSON());
}

rest.put(Routes.applicationGuildCommands(clientId, guildId), { body: commands })
    .then(() => console.log('Successfully registered application commands.'))
    .catch(console.error);
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

my deploy script is pretty much the same and works just fine. From the error message Cannot find module '../common' it looks like a require error.

I don't see a common require in you code example. Try finding that require and check your path with variations such as './common' or 'common' (if you don't know where it is you can run a project search with Ctrl + Maj + F)

It could be a file or a folder that was moved without refactoring.

I hope that's useful.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda