bot.command.有功能

问题描述 投票:0回答:1
const Discord = require('discord.js');

module.exports.run = async (bot, message, args) => {
 let helpArray = message.content.split(' ');
 let helpArgs = helpArray.slice(1);

 if (helpArgs[0] === 'gaming') {
  return message.reply('Gamings');
 }

 if (!helpArgs[0]) {
  const embed = new Discord.MessageEmbed()
   .setColor(`#f900ff`)
   .setTitle(`**Dragonite Commands:**`)
   .addFields(
    {
     name: '**:police_officer: Moderation:**',
     value:
      '**`!mute`**, **`!kick`**, **`!ban`**, **`!unban`**, **`!nickname`**, **`!clear`**',
    },
    {
     name: '**:sparkles: Misc:**',
     value:
      '**`!avatar`**, **`!ping`**, **`!info`**, **`!user`**, **`!server`**, **`!mute`**',
    }
   )
   .setFooter(
    'Dragonite | Requested by ' + message.author.tag,
    'https://i.imgur.com/3Oxc3I8.png'
   );

  return message.channel.send(embed);
 }

 if (helpArgs[0]) {
  let command = helpArgs[0];

  if (bot.command.has(command)) {
   command = bot.commands.get(command);
   const embed = new Discord.MessageEmbed()
    .setTitle(`Command Help: ${command.config.name}`)
    .setColor(`#f900ff`).setDescription(`
                **Name: ${command.config.name} || "N/A"
                **Description: ${command.config.description} || "N/A"
                **Usage: ${command.config.usage} || "N/A"
                **Example: ${command.config.example} || "N/A"
                `);
  } else
   return message.channel.send("**This command isn't available :warning:!**.");
 }
};
module.exports.help = {
 name: 'help',
 description: "Check a Dragonite's commands.",
 usage: 'user [@user | user ID]',
 example: 'user LeRegedit#1281',
};

错误:

(node:43856) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'has' of undefined

请忽略这个:敏捷的棕色狐狸跳过懒狗,敏捷的棕色狐狸跳过懒狗,敏捷的棕色狐狸跳过懒狗。

javascript node.js discord discord.js
1个回答
0
投票

应该是

bot.commands.has(...)
(你漏掉了“s”)

© www.soinside.com 2019 - 2024. All rights reserved.