Urban Dictionary Command Added

This commit is contained in:
dragonfire535
2017-03-03 07:01:06 -05:00
parent 7c8d12217e
commit cd695efbaa
2 changed files with 54 additions and 1 deletions
+52
View File
@@ -0,0 +1,52 @@
const commando = require('discord.js-commando');
const Discord = require('discord.js');
const urban = require('urban');
class UrbanDictionary extends commando.Command {
constructor(Client){
super(Client, {
name: 'urban',
group: 'response',
memberName: 'urban',
description: 'Searches Urban Dictionary. (;urban Cat)',
examples: [';urban Cat']
});
}
async run(message, args) {
if(message.channel.type !== 'dm') {
if(!message.channel.permissionsFor(this.client.user).hasPermission('SEND_MESSAGES')) return;
if(!message.channel.permissionsFor(this.client.user).hasPermission('READ_MESSAGES')) return;
if(!message.channel.permissionsFor(this.client.user).hasPermission('EMBED_LINKS')) return;
}
console.log("[Command] " + message.content);
let wordtodefine = message.content.split(" ").slice(1).join(" ");
urban(wordtodefine).first(function(json) {
if(json === undefined) {
message.reply(":x: Error! Word not found!");
} else if(json.definition === '') {
message.reply(":x: Error! Word has no definition!");
} else if(json.example === '') {
const embed = new Discord.RichEmbed()
.setColor(0x0000FF)
.setAuthor('Urban Dictionary', 'https://lh3.googleusercontent.com/4hpSJ4pAfwRUg-RElZ2QXNh_pV01Z96iJGT2BFuk_RRsNc-AVY7cZhbN2g1zWII9PBQ=w170', json.permalink)
.setDescription(json.word)
.addField('Definition:',
json.definition);
message.channel.sendEmbed(embed).catch(console.error);
} else {
const embed = new Discord.RichEmbed()
.setColor(0x0000FF)
.setAuthor('Urban Dictionary', 'https://lh3.googleusercontent.com/4hpSJ4pAfwRUg-RElZ2QXNh_pV01Z96iJGT2BFuk_RRsNc-AVY7cZhbN2g1zWII9PBQ=w170', json.permalink)
.setDescription(json.word)
.addField('Definition:',
json.definition)
.addField('Example:',
json.example);
message.channel.sendEmbed(embed).catch(console.error);
}
});
}
}
module.exports = UrbanDictionary;
+2 -1
View File
@@ -17,6 +17,7 @@
"discord.js-commando": "^0.9.0",
"google-translate-api": "^2.2.2",
"jimp": "^0.2.27",
"pirate-speak": "^1.0.1"
"pirate-speak": "^1.0.1",
"urban": "^0.3.1"
}
}