0

У меня есть бот дискорд, я хочу сделать чтоб у одной команды было два название, чтоб код один код отликался на два название !help и !commands, как мне это сделать ?

Мой код:

index.js
const Discord = require("discord.js");
const sdr     = new Discord.Client();
const fs      = require('fs');
sdr.commands  = new Discord.Collection();     

fs.readdir("./utils/", (err, files) => {

    if(err) console.log(err);
  
    let jsfile = files.filter(f => f.split(".").pop() === "js")
    if(jsfile.length <= 0){
      console.log("Не удалось найти команды.");
      return;
    }
  
    jsfile.forEach((f, i) =>{
      let props1 = require(`./utils/${f}`);
      console.log(`Loaded: ${f}`);
      sdr.commands.set(props1.help.name, props1);
    });
  
});

sdr.on("message", async message => {
    if(!message.guild)
    if(message.author.bot) return;

    if(message.channel.type === "dm") return;
    if(message.content.indexOf(settings.prefix) !== 0) return;

    let messageArray = message.content.split(" ");
    let cmd = messageArray[0];
    let args = messageArray.slice(1)
    
    let commandfile = sdr.commands.get(cmd.slice(config.prefix.length));
    if(commandfile) commandfile.run(sdr,message,args, settings, premiumakk);
});

help.js
const Discord = require('discord.js');

module.exports.run = async (bot, message, args) => {
const Embed = new Discord.MessageEmbed()
   .setTitle('Все команды')
   .setDescription('!help - показать все команды\n!ping - показать пинг')
message.channel.send(Embed);
}

module.exports.help = {
  name: "help",
  info: "help commands"
}

Я пробовал

module.exports.help = {
  name: ["help" || 'commands'], //name: ['help', 'commands'], //name: ['help', && 'commands']
  info: "help commands"
}

Но у меня ничего не получилось

3
  • Так "command" или "commands"? 13 дек 2020 в 12:05
  • Может покажете код основного файла? Без него ничего не получится
    – T0xee.n17
    13 дек 2020 в 13:15
  • T0hich71, извиняюсь, добавил 13 дек 2020 в 14:42

1 ответ 1

1

help.js

module.exports.help = {
  name: ["help","commands"],
  info: "help commands"
}

index.js

fs.readdir("./utils/", (err, files) => {

  if(err) console.log(err);

  let jsfile = files.filter(f => f.split(".").pop() === "js")
  if(jsfile.length <= 0){
    console.log("Не удалось найти команды.");
    return;
  }

  jsfile.forEach((f, i) =>{
    let props1 = require(`./utils/${f}`);
    console.log(`Loaded: ${f}`);
    if(typeof props1.help.name == "object") {
        props1.help.name.forEach(element => {
          sdr.commands.set(element, props1);
        });
    }
    else
      sdr.commands.set(props1.help.name, props1);
  });

});

Ваш ответ

Нажимая на кнопку «Отправить ответ», вы соглашаетесь с нашими пользовательским соглашением, политикой конфиденциальности и политикой о куки

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.