public static async Task <IDiscordMessage> SendToChannelAsync( this DiscordEmbed embed, IDiscordTextChannel channel) { if (channel is IDiscordGuildChannel guildChannel) { var currentGuildUser = await guildChannel.GetSelfAsync(); var permissions = await guildChannel.GetPermissionsAsync(currentGuildUser); if (!permissions.HasFlag(GuildPermission.EmbedLinks)) { if (!string.IsNullOrEmpty(embed.Image?.Url ?? "")) { using WebClient wc = new WebClient(); byte[] image = wc.DownloadData(embed.Image.Url); await using MemoryStream ms = new MemoryStream(image); return(await channel.SendFileAsync(ms, "output.png", embed.ToMessageBuilder().Build())); } else if (!string.IsNullOrEmpty(embed.Thumbnail?.Url ?? "")) { using WebClient wc = new WebClient(); byte[] image = wc.DownloadData(embed.Thumbnail.Url); await using MemoryStream ms = new MemoryStream(image); return(await channel.SendFileAsync(ms, "output.png", embed.ToMessageBuilder().Build())); } else { return(await channel.SendMessageAsync(embed.ToMessageBuilder().Build())); } } } return(await channel.SendMessageAsync("", embed : embed)); }
public static async Task <IDiscordMessage> EditAsync(this DiscordEmbed embed, IDiscordMessage msg) { var channel = await msg.GetChannelAsync(); if (channel is IDiscordGuildChannel guildChannel) { var currentGuildUser = await guildChannel.GetSelfAsync(); var permissions = await guildChannel.GetPermissionsAsync(currentGuildUser); if (!permissions.HasFlag(GuildPermission.EmbedLinks)) { return(await msg.EditAsync(new EditMessageArgs(embed.ToMessageBuilder().Build()))); } } return(await msg.EditAsync(new EditMessageArgs("", embed))); }