Create Urban command for discord bot by using discord.js 1

Create Urban command for discord bot by using discord.js

Hello guys, so in this post you are going to learn that how to create urban 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 youtube – https://www.youtube.com/playlist?list=PLDWSdP9KOAsc3v-dXaftI88RJAZONuhJ3

first we will take things which is needed to create this command. So we will install discord.js and urban package and this command will be simple and cool.

const Discord = require("discord.js");
const urban = require("urban");

Dont forget to install these packages from console and for that type this in console -> npm install discord.js urban . if these packages are alredy installed then there is no problem.

Now time to do some command stuff to define command.

module.exports = {
name: "urban",
category: "info",
usage: "urban <word>",
  run: async (client, message, args) => {
  
  //we gonna code here
  }
  }
  

Before anything add this statement

urban(args).first(json => {

now we will take args and check by json if the word really exist in search if not then send error message.

if (!json) return message.channel.send({
      embed: {
        "description": "Nothing found :sweat: ",
        "color": 0xFF2222
      }
    });

If you want to check if user had written any word then you can check statement which is very easy but in this post i only will show you main things.

Now its time to send embed with full of info.

let embed = new Discord.RichEmbed()
      .setColor(0x56aaff)
      .setDescription(json.definition)
      .addField('Example', json.example)
      .addField(`Upvotes`, json.thumbs_up, true)
      .addField(`Downvotes`, json.thumbs_down, true)
      .setFooter(`Written by ${json.author}`)
      .setTitle(json.word);

    message.channel.send(embed);

All is done now and if you want to see resulting code then here it is

const Discord = require("discord.js");
const urban = require("urban");

module.exports = {
name: "urban",
category: "info",
usage: "urban <word>",
  run: async (client, message, args) => {
urban(args).first(json => {

    if (!json) return message.channel.send({
      embed: {
        "description": "Nothing found :sweat: ",
        "color": 0xFF2222
      }
    });

    let embed = new Discord.RichEmbed()
      .setColor(0x56aaff)
      .setDescription(json.definition)
      .addField('Example', json.example)
      .addField(`Upvotes`, json.thumbs_up, true)
      .addField(`Downvotes`, json.thumbs_down, true)
      .setFooter(`Written by ${json.author}`)
      .setTitle(json.word);

    message.channel.send(embed);
});
  }
}

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

Related Posts

Leave a Reply

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