def define(self, ctx, *, word : str):
"""Gives the definition of the word passed."""
# Check if we're suppressing @here and @everyone mentions
if self.settings.getServerStat(ctx.message.server, "SuppressMentions").lower() == "yes":
suppress = True
else:
suppress = False
if not word:
msg = 'Usage: `{}define [word]`'.format(ctx.prefix)
await self.bot.send_message(ctx.message.channel, msg)
return
url = "http://api.urbandictionary.com/v0/define?term={}".format(quote(word))
msg = 'I couldn\'t find a definition for "{}"...'.format(word)
r = requests.get(url, headers = {'User-agent': self.ua})
theJSON = r.json()["list"]
if len(theJSON):
# Got it - let's build our response
ourWord = theJSON[0]
msg = '__**{}:**__\n\n{}'.format(string.capwords(ourWord["word"]), ourWord["definition"])
if ourWord["example"]:
msg = '{}\n\n__Example(s):__\n\n*{}*'.format(msg, ourWord["example"])
# await self.bot.send_message(ctx.message.channel, msg)
# Check for suppress
if suppress:
msg = Nullify.clean(msg)
await Message.say(self.bot, msg, ctx.message.channel, ctx.message.author)
评论列表
文章目录