Zack Arnett
Zack Arnett

Reputation: 259

How to use Embedding with C#? Discord BOT

I am looking to embed the following: Embed Pic

Using the Discord API. I have looked and the only resources I can find are for Python, Java, Ruby, etc.

But when using:

var embed = new Message.Embed(
{
    Author =
    {
        Name = "Name",
        Url = "www.url.com"
    }
});

It comes back with the message:

Error on MEssage.Embed

And:

Error on Name and URL

Not sure What I need to do to be able use the embed library. Just looking for some guidance on how this works

Edit:

When Using this I get no errors but when running the embed doesnt seem to build. It doesnt error. It just never builds the embed variable

var embed = new Message.Embed
            {
                Author =
                {
                Name = "Lawler",
                Url = "www.twitch.tv/Lawler"
                },
                Title = "www.twitch.tv/Lawler",
                Thumbnail =
                {
                ProxyUrl = "https://yt3.ggpht.com/-m-P7t2g-ecQ/AAAAAAAAAAI/AAAAAAAAAAA/YtS2YsD8-AM/s900-c-k-no-mo-rj-c0xffffff/photo.jpg",
                Url = "www.twitch.tv/Lawler"
                },
                Description = "**Now Playing**\n" +
                              "Rocket League\n" +
                              "**Stream Title**\n" +
                              "Lawler RLCS Caster"

            };

*Note: I am using Discord v 0.9.6

Upvotes: 1

Views: 19529

Answers (4)

Ruan Montelo
Ruan Montelo

Reputation: 191

You can create an Embed Message like the following code (using the most recent version of Discord.Net):

var builder = new EmbedBuilder()
{
    //Optional color
    Color = Color.Green,
    Description = "This is the description of the embed message"
};

Build a field inside the Embed Message:

builder.AddField(x =>
{
    x.Name = Author.Name;
    x.Value = Author.Url;
    x.IsInline = false;
});

And reply to the same channel context:

//Use await if you're using an async Task to be completed.
await ReplyAsync("", false, builder.Build())

The code above should build an embed message, there are more options in the Discord.Net docs. Link: https://docs.stillu.cc/guides/introduction/intro.html

I hope you find this helpful.

Upvotes: 2

ComedicChimera
ComedicChimera

Reputation: 476

If you are in Discord.Net 1.0.1, you can format an embed like so:

var eb = new EmbedBuilder() { Title = "Cool Title", Description = "Description" };

Read the documentation here for more info here.

And if you want to make your text look a little better, you can read the Discord Markdown Documentation here. This works in 0.9.6.

To send an embed use:

await Context.Channel.SendMessageAsync("", false, eb);

Upvotes: 1

datboi
datboi

Reputation: 198

    var embed = new EmbedBuilder()

instead of

var embed = new Message.Embed()

To send the message:

   await Context.Channel.SendMessageAsync("", false, embed);

EDIT: 0.9.6 doesn't support embeds, so the code above is useless

Upvotes: 1

Adam Schiavone
Adam Schiavone

Reputation: 2452

Just a quick look at your code, I think you've got a close parenthesis in the wrong place.

Try the following:

var embed = new Message.Embed()
{
    Author =
    {
        Name = "Name",
        Url = "www.url.com"
    }
};

Again, without doing any research you may also need to do the following:

var embed = new Message.Embed()
{
    Author = new Author()
    {
        Name = "Name",
        Url = "www.url.com"
    }
};

Upvotes: 1

Related Questions