【问题标题】:C# Discord.net Add File as Image to EmbedC# Discord.net 将文件作为图像添加到嵌入
【发布时间】:2021-11-20 00:08:00
【问题描述】:

如何将本地文件添加到我的嵌入为图像。

我不想将它上传到 imgur 或任何东西并获取 URL。由于更改了图像,这对项目不起作用。

我现在的代码:


                var emb = new EmbedBuilder()
                    .WithColor(Color.Blue)
                    .WithTimestamp(DateTime.Now)
                    .WithTitle(rarity)
                    .WithDescription($"{Context.User.Username} dropped a card!")
                    .WithImageUrl($"attachment://{path}")
                    .Build();

                await Context.Channel.SendFileAsync(path, null, false, emb);

【问题讨论】:

标签: c# discord.net


【解决方案1】:
                var filename = Path.GetFileName(path);

                var emb = new EmbedBuilder()
                    .WithImageUrl($"attachment://{filename}")
                    .Build();

                await Context.Channel.SendFileAsync(path, null, false, emb);

Path.GetFileName 使我能够与attachment://{filename} 结合使用

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-03
    • 1970-01-01
    • 1970-01-01
    • 2020-10-11
    • 2023-03-07
    • 2014-09-28
    相关资源
    最近更新 更多