修改异步不工作

ModifyAsync Not Working

我正在尝试编辑已发布的嵌入消息。我试图使用文档中的这个示例,但它不起作用。 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.");
});

将代码放入我的一个工作命令中会得到

cannot implicitly convert type Discord.EmbedBuilder to Discord.Optional<Discord.Embed>"

真的很迷茫...

您在 WithDescription 之后缺少 .Build()。通常在使用构建器模式时,您通常需要 构建 所需的类型。

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.
});

调用 Build() 会 return 一个 Embed 然后可以隐式转换为 Optional<Embed>"