Discord help command

I am having some issues with my help command, when i want to get some information about a command

   const Discord = require("discord.js");
   const { MessageEmbed } = require("discord.js");
   const { COLOR, PREFIX } = require("../../config.js");

module.exports = {
config: {
name: “help”,
aliases: [“h”],
description: “Help Command!”,
usage: "Help | ",
},
run: async(client, message, args) => {

    let embed = new MessageEmbed()
    .setColor(COLOR)
    .setTitle(`${client.user.username} Commands!`)
    .setDescription(`Use ${PREFIX}Help <Command Name> For More Command Information!` + 
    "\n\n**Economy**\n`Addmoney, Balance, Beg, Buy, Daily, Deposit, Fish, Leaderboard, Pay, Removemoney, Rob, Roulette, Sell, Setbackground, Setinfo, Slots, Store, Weekly, Withdraw, Work`" + "\n\n" + "**Fun**\n`Ascii, Calculate, Coinflip, Dog, Hack, Howgoofy, Howjajaja, Meme, Motivation, Randomnumber, Rate, Roast, Say, Snipe, Status, Tts, Urbandictionary`" + "\n\n" +
    "**Games**\n`Akinator, Blackjack, Connectfour, Duelquiz, Gunfight, Horserace, Memory, Poker, RPS, Russianroulette, Tictactoe, Trivia`" + "\n\n" + "**Image**\n`Avatar, Avatarfusion, Captcha, Clyde, Faceplam, Fire, Gif, Jail, Mission, Scary, Tobecontinued, Triggered, Tweet, Wasted`" + "\n\n" +  "**Music**\n`Join, Leave, Loop, Musictrivia, Nowplaying, Pause, Play, Queue, Remove, Resume, Search, Shuffle, Skip, Skipall, Skipto, Stop, Stopmusictrivia, Volume`" + "\n\n" +  
    "**Information**\n`Calladmin, Channelinfo, Feedback, Help, Instasearch, Invites, Level, News, Ping, Poll, Roleinfo, Rolememberinfo, Serverinfo, Translate, Uptime, Weather, Whois, Wikipedia`")
    .setFooter(`Requested By ${message.author.username}`)
    .setTimestamp();
    
    if (!args.length) return message.channel.send(embed);

    let cmd =
      client.commands.get(args[0].toLowerCase()) ||
      client.commands.get(client.aliases.get(args[0].toLowerCase()));

    let embed2 = new MessageEmbed()
      .setColor(COLOR)
      .setTitle(`${cmd.name} Information!`)
      .addField(`Aliases`, cmd.aliases || "None!")
      .addField(`Usage`, cmd.usage || "No Usage")
      .addField(`Description`, cmd.description || "No Description!")
      .setTimestamp();

    if (cmd) {
      return message.channel.send(embed2);
    } else {
      return message.channel.send(embed);
    }
  }
};

Here my error

(node:7824) UnhandledPromiseRejectionWarning: TypeError: Cannot read property ‘name’ of undefined

At Object.run (/app/commands/info/help.js:33:24)

At module.exports (/app/events/guild/message.js:34:38)

at processTicksAndRejections (internal/process/task_queues.js:88:5)

(node:7824) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)

(node:7824) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code._

Anyone have an idea?

Essentially you have a problem here because cmd was not found:

     let embed2 = new MessageEmbed()
      .setColor(COLOR)
      .setTitle(`${cmd.name} Information!`)

…so cmd.name causes an error.

I notice that below that, you have this in case cmd is null:

    if (cmd) {
      return message.channel.send(embed2);
    } else {
      return message.channel.send(embed);
    }

So you could move the whole let embed2 = ... statement inside the if branch, so that it only runs if cmd is set to something :slight_smile:

Hope it helps

4 Likes

Thanks for your response! But now it sends nothing :(. Just to be sure… Do I remove:
return message.channel.send(embed2);
And replace it by the let embed2 = ...?

no no, just move the let embed2 ABOVE the message.channel.send

2 Likes

Now I get this :frowning:

It suppose to fetch the info like this:

    config: {
        name: 'meme',
        aliases: ['memes'],
        description: 'Get a random meme',
        category: "fun",
        usage: ' ',
        accessableby: "everyone"
    },   
run: async (bot, message, args) => {

By sending this message I found out my error… I had to add a config. Thanks alot :smiley: