0
 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.

Csaas3311
  • 13
  • 5
  • Does this answer your question? [Discord.Net 1.0 How to use ModifyAsync/How to modify contents of a message](https://stackoverflow.com/questions/46095112/discord-net-1-0-how-to-use-modifyasync-how-to-modify-contents-of-a-message) – Chris Schaller Dec 26 '21 at 23:12
  • You need to await the Async calls if you need them to run in sequence – Chris Schaller Dec 26 '21 at 23:13
  • @ChrisSchaller I am not sure what you mean by this. I just want them to run one at a time. So my current method is correct, right? – Csaas3311 Dec 27 '21 at 00:18
  • @ChrisSchaller Also, I just need to edit the message using the ID. The first line that sends the message was just a one time thing. Now I will just edit that message. – Csaas3311 Dec 27 '21 at 00:20
  • Action funct @ChrisSchaller what is that used for? How do I use this to modify my message. This parameter is giving me trouble. – Csaas3311 Dec 27 '21 at 00:39
  • No, it's not correct. It's highly likely that this is going to dispose the client while the request is in flight. If a method returns a task, you need to do something with it (ideally await it). – Etienne de Martel Dec 27 '21 at 01:54
  • @EtiennedeMartel Can I please have some guidance on how to do this and how to send the request to modify the message? I have had no help. – Csaas3311 Dec 27 '21 at 01:58

1 Answers1

0

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.

Huron
  • 1,055
  • 1
  • 9
  • 16