【问题标题】:ModifyAsync Not Working修改异步不工作
【发布时间】:2018-05-20 05:12:18
【问题描述】:

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

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

无法将类型 Discord.EmbedBuilder 隐式转换为 Discord.Optional<Discord.Embed>"

真的很迷茫……

【问题讨论】:

  • 您在WithDescription 之后缺少.Build()

标签: c# discord.net


【解决方案1】:

您在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() 会返回一个Embed,然后可以隐式转换为Optional&lt;Embed&gt;"

【讨论】:

  • 完美运行!非常感谢。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-07-13
  • 2023-03-31
  • 1970-01-01
相关资源
最近更新 更多