'Discord.js how to make suggest command?

What can I do in Discord.js to make suggest command? My actual code doesn't work, i have 2 types of suggestions: support server and bot. Here's my code:

if (command === "suggest"){
    const type = args.join(" ")
    const thing = args.join(" ").slice(6)
    const thing2 = args.join(" ").slice(3)
    const suggestion = new Discord.RichEmbed()
       .setTitle("New suggestion!")
   .setAuthor(`${message.author.tag}`, `${message.author.avatarURL}`)
    .addField(`${message.author.tag}`, `suggested: ${thing}`)
    const suggestion2 = new Discord.RichEmbed()
       .setTitle("New suggestion!")
   .setAuthor(`${message.author.tag}`, `${message.author.avatarURL}`)
    .addField(`${message.author.tag}`, `suggested: ${thing2}`)
    if (!typ){
     message.reply("enter suggestion type, which you want to suggest!");
      return;
    }
            if (type === "server"){
               if (!thing){
     message.reply("enter thing you want to suggest!");
      return;
    }
      client.channels.get("channel_id").send(suggestion);
      return;
    }
    if (type === "bot"){
      if (!suggestion2){
     message.reply("enter thing you want to suggest!");
      return;
    }
      client.channels.get("another_channel_id").send(suggestion2);
      return;
    }
            else if (type !== "bot" || type !== "server"){
     message.reply("invalid suggestion type!"); 
    return;
        }
  }

and it outputs "invalid suggestion type!" when I type !suggestion



Solution 1:[1]

I'm not an expert with discord.js but this should work! (It does on my server!)

client.on('message', msg => {    //This runs when a message is sent.
const args = msg.content.slice(prefix.length).split(' ');  //Get the arguments
const command = args.shift().toLowerCase();  //Making the command non case-sensitive


if (command === 'suggest'){   //if command is suggest
const channel = msg.guild.channels.find(ch => ch.name === 'suggestions');  //finds the channel named suggestions 

channel.send('Suggestion:\n ' + args.join(' '))  //Sends the arguments
}     //Closes the if (command === 'suggest'){ 
});   //Closes the client.on('message',msg => {

Great if i can help!

Also you used !== so if user is not a bot it doesn't send message. Try using === instead!

Solution 2:[2]

I dont know if you use a command handler or not but if you do, this should work:

if (command === 'suggest'){

    const Discord = require('discord.js'); // this should be on top of ur js file, NOT HERE
    const { Client, MessageEmbed } = require('discord.js'); // this should be on top of ur js file, NOT HERE

    if(!args[0]) return message.reply('You need to type a suggestion..') // bot reply if user only typed !suggest n didnt include any text..

    const user_avatar = message.author.avatarURL({ format: 'png', dynamic: true, size: 2048 }); // gets discord user avatar
    const user_suggestion = args.slice(0).join(" ") // gets discord user args

    let suggestion_channel = message.guild.channels.cache.find(
        (cache) => cache.name === "suggestions" // the channel name u want the embed to be sent to..
    );
    if (!suggestion_channel) return;


    const suggestion_emb = new MessageEmbed() // The suggestion embed that will be sent to the "suggestions" channel
     .setAuthor(`Suggestion:`, `${user_avatar + "?size=2048"}`)
      .setDescription(`${user_suggestion}`)
       .setColor("RANDOM") // randomizes the color of the embed, can also be hex n rgb so ".setColor("#3d71e7")" for example.
        .setFooter(`Suggested by: ${message.author.tag}`);

    const suggestion_reply_emb = new MessageEmbed() // the reply embed so when someone does !suggest suggestion here, it will reply with the embed below
     .setAuthor(`${message.author.tag}`, `${user_avatar + "?size=2048"}`)
      .setDescription(`:white_check_mark: Your suggestion has been sent to <#CHANNEL_ID_HERE>.`)
       .setColor("RANDOM");

    message.reply(suggestion_reply_emb) && suggestion_channel.send(suggestion_emb)
};

if u use a command handler just remove the first & last line

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Nemz