From c62f322bbc31e7fd85aa3a872f48955960f22b51 Mon Sep 17 00:00:00 2001 From: Luke Robles Date: Tue, 15 Sep 2020 13:23:53 -0700 Subject: [PATCH] make the defintion an embed --- app/bot.py | 2 +- app/define_word.py | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/app/bot.py b/app/bot.py index 5f1296cd..e5daaf58 100755 --- a/app/bot.py +++ b/app/bot.py @@ -207,7 +207,7 @@ async def dog(ctx): async def define(ctx): import define_word - await ctx.send(define_word.get_definition(ctx.message.content)) + await ctx.send(embed=define_word.get_definition(ctx.message.content)) @bot.command(name='greentext') async def greentext(ctx): diff --git a/app/define_word.py b/app/define_word.py index 65f194a1..167ac884 100644 --- a/app/define_word.py +++ b/app/define_word.py @@ -1,6 +1,9 @@ import requests import help_methods +import discord + + def get_definition(content): """ get_definition(content) @@ -13,6 +16,7 @@ def get_definition(content): definition = requests.get( "https://api.urbandictionary.com/v0/define?term={}".format('%20'.join(word)) ).json()['list'][0]['definition'] + site = 'Urban Dictionary' except IndexError: try: @@ -20,9 +24,14 @@ def get_definition(content): definition = requests.get( "http://api.pearson.com/v2/dictionaries/ldoce5/entries?headword={}".format('%20'.join(word)) ).json()['results'][0]['senses'][0]['definition'][0] + + site = 'Pearson' except IndexError: definition = 'No definition found' - return "`{}`\n```{}```".format(' '.join(word), definition) + embed = discord.Embed(description="%s:\n%s" % (' '.join(word), definition), color=0x428bca, type="rich") + embed.set_author(name="From %s" % site) + + return embed return help_methods.get_help_message('define')