问题
I'm attempting to edit an embedded message after it is posted. I was attempting to use this example from the documentation but it just does not work. https://discord.foxbot.me/docs/api/Discord.MessageProperties.html
var message = await ReplyAsync("abc");
await message.ModifyAsync(x =>
{
x.Content = "";
x.Embed = new EmbedBuilder()
.WithColor(new Color(40, 40, 120))
.WithAuthor(a => a.Name = "foxbot")
.WithTitle("Embed!")
.WithDescription("This is an embed.");
});
Putting the code into one of my working commands will give a
cannot implicitly convert type
Discord.EmbedBuilder
toDiscord.Optional<Discord.Embed>
"
Really confused...
回答1:
You are missing a .Build()
after WithDescription
. Usually when using the builder pattern you usually need to build the desired type.
var message = await ReplyAsync("abc");
await message.ModifyAsync(x =>
{
x.Content = "";
x.Embed = new EmbedBuilder()
.WithColor(new Color(40, 40, 120))
.WithAuthor(a => a.Name = "foxbot")
.WithTitle("Embed!")
.WithDescription("This is an embed.")
.Build(); //<-- The is what was omitted.
});
Calling Build()
would return a Embed
which can then be implicitly converted to Optional<Embed>"
来源:https://stackoverflow.com/questions/47672300/modifyasync-not-working