def randefine(self, ctx):
"""Gives a random word and its definition."""
url = "http://api.urbandictionary.com/v0/random"
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)
await Message.say(self.bot, msg, ctx.message.channel, ctx.message.author)
评论列表
文章目录