Discord.Net 1.0 How to use ModifyAsync/How to modify contents of a message

13k Views Asked by At

I'm trying to edit a message that my bot sent, but I can't seem to find any answers by myself. For context, the old message is a "waiting" message until the API I'm using retrieves the data I want. The new message is what the data that was received.

This is my current solution:

var msg = await ReplyAsync("old message");

//... unrelated code ...    

await msg.DeleteAsync();
await ReplyAsync("new message");

The arguments for ModifyAsync(); are Action<MessageProperties> funct, [RequestOptions options].

I've attempted to use ModifyAsync(); myself, to no avail.

All I want to do is modify the content of the message, and all of the research I've done leads to earlier versions of the Discord.Net library.

How can I do this correctly?

2

There are 2 best solutions below

3
On

I did some research and found this : https://github.com/RogueException/Discord.Net/issues/474

I know it isn't modifying a message but it works the same way, you pass it a lambda expression:

var Message = await Context.Channel.SendMessageAsync("test message");

await Message.ModifyAsync(msg => msg.Content = "test [edited]");
1
On
await Context.Channel.SendMessageAsync("Test.");
await Context.Message.ModifyAsync(m => { m.Content = "Test [Edited]."; });

I hope that helps