UrbanDict.py 文件源码

python
阅读 32 收藏 0 点赞 0 评论 0

项目:CorpBot.py 作者: corpnewt 项目源码 文件源码
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)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号