# Using Embeds

## Preview

You will be using something called Discord embeds to make your responses look ever nicer! You can add a title to your message, a description, and a color off to the side.&#x20;

![](https://5148195-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MgIjc7Q-SbTUf-t61Rv%2F-MlXTGdbjQZHktniArv5%2F-MlXWLh5aQQyObmhIAOv%2Fimage.png?alt=media\&token=020d1ffe-0c63-40ee-b6d2-4150a4da3d8f)

## Coding

We will be editing our hello command (below) which we had written previously to be like the image above.

```python
@client.command(pass_context=True)
async def hello(message):
  await message.channel.send(f"Hello {message.author.name}")
```

We can delete the line await `message.channel.send(f"Hello {message.authro.name}")` as we will be writing it from scratch to send it with an embed.

First, we need to create the actual embed we will be sending. This is a little different than sending a message like we did before as we will be needing to create the embed object . An object is like a container, think of a box, it contains a bunch of different things inside of it. An object will have a bunch of information about it inside of it.

So how do we create this object? Well, we can use a variable, lets called it embed. We can create a new embed by referencing the discord variable we created before and finding the premade Embed object. We can do this by typing `embed = discord.Embed()`. Inside of the parenthesis, like how we did it before, we can include "settings". To properly format it, press enter between the 2 parenthesis. It should look something like this:

```python
embed = discord.Embed(

)
```

Now we can fill out the settings. The first thing is the title. In the example picture the word `"Hello"` is the title. You can name this whatever you want, but for this case lets set it to `"Hello"`. To do this we can type out (in the parenthesis) `title = "Hello",` (make sure to include the comma after it).

Now we can add a description. In the example picture `"Hello krishrenjen"` is the description. To do this is is pretty similar to adding a title except you change title to description. It would be as follows: `description = f"Hello {message.author.name}",` (remember how we use f strings).

Now lets add a little color. In the example image there is a color bar on the left side of the embed. We can set this to any color we want. It is similar to how we did it before except with a slight twist. We can start with `color =` like before but instead of typing the color we want, we have to do something different.\
You have to use `discord.Color.[color name](),` replacing `[color name]` with the name of the color you want from the list below. For example, `color = discord.Color.blue(),`.

A list of colors you can use (must be spelled exactly as what is shown below):&#x20;

* teal
* dark\_teal
* brand\_green
* dark\_green
* blue
* dark\_blue
* purple
* dark\_purple
* magenta
* gold
* dark\_gold
* orange
* dark\_orange
* brand\_red
* red
* dark\_red
* lighter\_gray
* dark\_gray
* light\_gray
* darker\_gray
* blurple
* fuchsia
* yellow

```python
@client.command(pass_context=True)
async def hello(message):
  embed = discord.Embed(
    title = "Hello",
    description = f"Hello {message.author.name}",
    color = discord.Color.blue(),
  )
```

Now all we need to do is send the embed. Use

```python
await message.channel.send(embed=embed)
```

Lets break this piece of code down. You use the await `message.channel.send` to send a message to the channel. Then you use `embed =` to show that you are sending an embed. Then after that you put what you called the embed, in this case we called it the same thing, `embed`.



{% tabs %}
{% tab title="Instructions" %}
Only select the **Final Code** tab once you have **completed** your embed command. If you are stuck please see a mentor.
{% endtab %}

{% tab title="Final Code" %}
```python
@client.command(pass_context=True)
async def hello(message):
  embed = discord.Embed(
    title = "Hello",
    description = f"Hello {message.author.name}",
    color = discord.Color.blue(),
  )

  await message.channel.send(embed=embed)
```
{% endtab %}
{% endtabs %}



## Code Checkup

Your code should look something like the following at this point in the sushi card, except it will contain your custom commands:

{% tabs %}
{% tab title="Instructions" %}
Only select the **Final Code** tab once you have **completed** this section. If you are stuck please see a mentor.
{% endtab %}

{% tab title="Final Code" %}
```python
import os
import discord
from discord.ext import commands
import random

token = os.environ['token']

client = commands.Bot(command_prefix = "!", case_insensitive=True)

@client.event
async def hello(message):
  embed = discord.Embed(
    title = "Hello",
    description = f"Hello {message.author.name}",
    color = discord.Color.blue(),
  )

@client.command(pass_context=True)
async def hello(message):
  await message.channel.send(f"Hello {message.author.name}")

@client.command(pass_context=True)
async def eightball(message, *, arg):
  responses = ["Response 1",
  "Response 2",
  "Response 3"]

  answer = random.choice(responses)

  await message.channel.send(f"You asked: {arg}\nMy response: {answer}")


client.run(token)
```
{% endtab %}
{% endtabs %}

If your code is not like this or is not working, please either read through the sushi card again OR come talk to one of the mentors who will guide you through the issue.
