ModifyAsync Not Working

最后都变了- 提交于 2021-01-27 19:55:33

问题


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 to Discord.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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!