Create suggest command in discord.js 1

Create suggest command in discord.js

Hello guys, so in this post you are going to learn that how to create suggest command in discord.js and i will do coding in glitch.com. if you dont know how to create discord bot in android by discord.js then you must watch our series in youtubehttps://www.youtube.com/playlist?list=PLDWSdP9KOAsc3v-dXaftI88RJAZONuhJ3

Now first create new file with name suggest.js

Create suggest command in discord.js 2
commands/category/command name <= this is order

now first we install some packages that we needed

Create suggest command in discord.js 3
this all that we needed

now we gonna make something for help command.

const { RichEmbed } = require("discord.js");

module.exports = {
    name: "suggest",
  category: "main",
  usage: "<message>",
    description: "suggest anything you wanted to",
    run: async (bot, message, args) => {

}
}

its time to we get started, i think we should delete author message then send bot message , it will look more cool. So for that we gonna use message.delete() , after that we should let the suggestion message by args like this -> let suggestion = args.join(” “);

Now we have to check if the author has given the suggestion message or not and for that we gonna use if statement.

if (!suggestion)
      return message.channel
        .send(`Please provide a suggestion!`)
        .then(m => m.delete(15000));

Now its time to let channel where we are going to send this suggestion message, so for making this simple we will find channel by its name that will be cool and amazing and after that we have to check if does have channel with that name.

 let sChannel = message.guild.channels.find(x => x.name === "suggestions");
      if(!sChannel) return message.channel.send("You dident have channel with name `suggestions`")

after that all trouble its time to send message to channel if it exist, we will send message in embed by using RichEmbed and before that we will send a simple message to user that we have sended your suggestion!

 message.channel 
      .send("Your suggestion has been filled to the staff team. Thank you!")
      .then(m => m.delete(15000));

its time to send embed for that you only need to do is to create embed and suggestion message. The main thing dont forget to add author name in embed so we get to know who sended the amazing suggestion. for embed you have to code like this.

 let suggestembed = new RichEmbed()
      .setFooter(bot.user.username, bot.user.displayAvatarURL)
      .setTimestamp()
      .addField(`New Suggestion from:`, `**${message.author.tag}**`)
      .addField(`Suggestion:`, `${reason}\n**Its your choice!**`)
      .setColor('#ff2052');
    sChannel.send(suggestembed).then(async msg => {
      await msg.react("✅");
      await msg.react("❌");
    });

we added reacions in suggestion, so it looks really cool… Now its completed so if you want to see resulting code then i am putting codes here.

Table of Contents

Result codes

const { RichEmbed } = require("discord.js");

module.exports = {
    name: "suggest",
  category: "main",
  usage: "<message>",
    description: "suggest anything you wanted to",
    run: async (bot, message, args) => {
    message.delete()
    // reasoning definition
    let suggestion = args.join(" ");
    if (!suggestion)
      return message.channel
        .send(`Please provide a suggestion!`)
        .then(m => m.delete(15000));

    // grab reports channel
    let sChannel = message.guild.channels.find(x => x.name === "suggestions");
      if(!sChannel) return message.channel.send("You dident have channel with name `suggestions`")
    // send to reports channel and add tick or cross
    message.channel 
      .send("Your suggestion has been filled to the staff team. Thank you!")
      .then(m => m.delete(15000));
    let suggestembed = new RichEmbed()
      .setFooter(bot.user.username, bot.user.displayAvatarURL)
      .setTimestamp()
      .addField(`New Suggestion from:`, `**${message.author.tag}**`)
      .addField(`Suggestion:`, `${suggestion}\n**Its your choice!**`)
      .setColor('#ff2052');
    sChannel.send(suggestembed).then(async msg => {
      await msg.react("✅");
      await msg.react("❌");
    });
  }
};
 

Conclusion

if you had any problem then you can join our discord server for help – https://discord.gg/cV2ENjt

Leave a Reply

Your email address will not be published. Required fields are marked *