'Modifying WebHook Message With Discord.Net c#

 using (DiscordWebhookClient client = new DiscordWebhookClient(WEBHOOK_URL))
{
   ulong z = 42342340290226;

   client.ModifyMessageAsync(z);//Not sure how I would edit this message. The documentation is confusing.
}

Im not sure how to use this ModifyMessage function. Also, do I need to use a Async Function? I am just calling it without using any ASYNC. Im not sure if that is ok. The send message works, but second function im not sure how to work it.



Solution 1:[1]

Like others have said, you should await the async call. This ensures that the action is executed in a predictable fashion. The intend is to execute it right now and to wait for the result of the action.

That being said, the discord documentation describes this method as follows:

public Task ModifyMessageAsync(ulong messageId, Action<WebhookMessageProperties> func, RequestOptions options = null)

The second parameter describes a delegate based on WebhookMessageProperties. It can easily be defined by a lambda, like such:

x => { }

Now bear in mind the x is arbitrary, you can chose whatever designation you like, even whole words, I just kept it short for the example.

Between the bracelets, you can use access any properties that are in the WebhookMessageProperties class, by using x.SomeProperty. Where SomeProperty has to be a known property of that class if that makes sense.

One of the known properties is for example:

string Content { get; set; }

So here is how you can use a lambda to change the Content property:

using (DiscordWebhookClient client = new DiscordWebhookClient(WEBHOOK_URL))
{
    ulong z = 42342340290226;

    await client.ModifyMessageAsync(z, x => 
    {
        x.Content = "This is the updated message content";
    });

}

If you want to update multiple properties at the same time, you can just add another line inside the lambda.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Huron