T
T
TolaF2020-04-13 14:06:50
JavaScript
TolaF, 2020-04-13 14:06:50

How to combine several js files in a bot?

Please tell me what code can I run several others in a .js file?

Let's say I have several codes, the first one is for music, the second one is for messages, etc.
How to start them so that they work together?

Thanks in advance.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Kiljko, 2020-04-14
@kiidii_aniname

I understand that you have several commands and you want to scatter them into files, the simplest solution is this:
Create a commands folder next to the index.js file (Well, or what file do you run there)
file commands/music.js

module.exports = (message) => {
  // Код для музыкального файла
}

FILE commands/otherCommand.js
module.exports = (message) => {
  // Код другой команды
}

And in the main file (I have it index.js)
const musicCommand = require('./commands/music.js');
const otherCommand = require('./commands/otherCommand.js');

client.on('message', msg => {
  if (msg.content === 'music') {
    musicCommand(msg);
  }

  if (msg.content === 'other') {
    otherCommand(msg);
  }
});

Be sure to watch this video

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question