links.py 文件源码

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

项目:Bonfire 作者: Phxntxm 项目源码 文件源码
def urban(self, ctx, *, msg: str):
        """Pulls the top urbandictionary.com definition for a term

        EXAMPLE: !urban a normal phrase
        RESULT: Probably something lewd; this is urban dictionary we're talking about"""
        url = "http://api.urbandictionary.com/v0/define"
        params = {"term": msg}
        try:
            data = await utils.request(url, payload=params)
            if data is None:
                await self.bot.send_message(ctx.message.channel, "Sorry but I failed to connect to urban dictionary!")
                return

            # List is the list of definitions found, if it's empty then nothing was found
            if len(data['list']) == 0:
                await self.bot.say("No result with that term!")
            # If the list is not empty, use the first result and print it's defintion
            else:
                await self.bot.say(data['list'][0]['definition'])
        # Urban dictionary has some long definitions, some might not be able to be sent
        except discord.HTTPException:
            await self.bot.say('```\nError: Definition is too long for me to send```')
        except KeyError:
            await self.bot.say("Sorry but I failed to connect to urban dictionary!")
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号