#Building Embed Helper Extensions

1 messages · Page 1 of 1 (latest)

zinc saffron
#

Hello,

I am trying to create a few Embed Builder helpers and was wondering if anyone has any ideas for a better approach. Currently I'm creating extensions based off of strings.

public static Embed ToSuccessfulEmbed(this string description, string? title = null, string? thumbnailUrl = null,
        string? imageUrl = default, (string name, string iconUrl, string url) author = default, DateTimeOffset? timeStamp = default)
    {
        return description.ToEmbedBuilder(title, thumbnailUrl, imageUrl, Color.Green, author, timeStamp).Build();
    }

    public static EmbedBuilder ToEmbedBuilder(this string description, string? title = null, string? thumbnailUrl = null,
        string? imageUrl = null, Color color = default, (string name, string iconUrl, string url) author = default,
        DateTimeOffset? timeStamp = default)
    {
        var builder = new EmbedBuilder()
            .WithTitle(title)
            .WithDescription(description)
            .WithColor(color)
            .WithThumbnailUrl(thumbnailUrl)
            .WithImageUrl(imageUrl);

        if (timeStamp != default)
            builder.Timestamp = DateTimeOffset.UtcNow.ConvertToDiscordTimestamp(TimestampFormat.RelativeTime);

        if (author != default)
            builder.WithAuthor(author.name, author.iconUrl, author.url);

        return builder;
    }
mossy pewter
#

why not work with the builder directly

zinc saffron
mossy pewter
#

yes

#

you can do this EmbedBuilder

#
public static EmbedBuilder WithErrorColor(this EmbedBuilder eb) => eb.WithColor(Mewdeko.ErrorColor)
#

ez

zinc saffron
#

That is much better! Thank you so much

mossy pewter
#

np

zinc saffron
#

One more question if you dont mind

mossy pewter
#

?

zinc saffron
#

#useful-snippets message

topaz ploverBOT
zinc saffron
#

Per this, how can I use this as the Timestamp since the timestamp is a datetimeoffset

#

Or would it not work in that way

mossy pewter
#

TimestampTag.FromDateTimeOffset

zinc saffron
#

Don't see a TimestampTag

mossy pewter
zinc saffron
#

using Discord;

#

Def have that

#

It's part of EmbedBuilder correct?

mossy pewter
#

no its separate

zinc saffron
#

Oooo thank you so much @mossy pewter

mossy pewter
zinc saffron
mossy pewter
#

you can if you want

zinc saffron
#

Wait actually @mossy pewter still having an issue.

builder.Timestamp = TimestampTag.FromDateTimeOffset(DateTimeOffset.UtcNow.ConvertToDiscordTimestamp(TimestampFormat.RelativeTime));

#

Still a string error

mossy pewter
#

oh that type of timestamp

zinc saffron
#

FormatFromDateTimeOffset

mossy pewter
#

wait im confused and im probably gonna say something wrong so wait on someone else to answer lel

zinc saffron
#

Ah okay

mossy pewter
#

its 2am and brain is half fried

zinc saffron
#

haha np

#

Essentially I need to convert to DateTimeOffset builder.Timestamp = TimestampTag.FromDateTimeOffset(DateTimeOffset.UtcNow.ConvertToDiscordTimestamp(TimestampFormat.RelativeTime));, but the problem is with the Discord timestamps it's a string such as $"<t:{dateTime.ToUnixTimeSeconds()}:{format.Flag()}>";

zinc saffron
#

@mossy pewter Mind adding me as a friend? Have a question for ya and don't wanna clog this post

mossy pewter
#

added

rocky tinsel
#

tldr on second question, op wanted to make embed .WithTimestamp display user local time
I don't know if that's possible and footer do not support timestamps tags too