@@ -21,7 +21,7 @@ namespace Discord.Webhook
return RestInternalWebhook.Create(client, model);
return RestInternalWebhook.Create(client, model);
}
}
public static async Task<ulong> SendMessageAsync(DiscordWebhookClient client,
public static async Task<ulong> SendMessageAsync(DiscordWebhookClient client,
string text, bool isTTS, IEnumerable<Embed> embeds, string username, string avatarUrl, RequestOptions options)
string text, bool isTTS, IEnumerable<Embed> embeds, string username, string avatarUrl, AllowedMentions allowedMentions, RequestOptions options)
{
{
var args = new CreateWebhookMessageParams(text) { IsTTS = isTTS };
var args = new CreateWebhookMessageParams(text) { IsTTS = isTTS };
if (embeds != null)
if (embeds != null)
@@ -30,19 +30,21 @@ namespace Discord.Webhook
args.Username = username;
args.Username = username;
if (avatarUrl != null)
if (avatarUrl != null)
args.AvatarUrl = avatarUrl;
args.AvatarUrl = avatarUrl;
if (allowedMentions != null)
args.AllowedMentions = allowedMentions.ToModel();
var model = await client.ApiClient.CreateWebhookMessageAsync(client.Webhook.Id, args, options: options).ConfigureAwait(false);
var model = await client.ApiClient.CreateWebhookMessageAsync(client.Webhook.Id, args, options: options).ConfigureAwait(false);
return model.Id;
return model.Id;
}
}
public static async Task<ulong> SendFileAsync(DiscordWebhookClient client, string filePath, string text, bool isTTS,
public static async Task<ulong> SendFileAsync(DiscordWebhookClient client, string filePath, string text, bool isTTS,
IEnumerable<Embed> embeds, string username, string avatarUrl, RequestOptions options, bool isSpoiler)
IEnumerable<Embed> embeds, string username, string avatarUrl, AllowedMentions allowedMentions, RequestOptions options, bool isSpoiler)
{
{
string filename = Path.GetFileName(filePath);
string filename = Path.GetFileName(filePath);
using (var file = File.OpenRead(filePath))
using (var file = File.OpenRead(filePath))
return await SendFileAsync(client, file, filename, text, isTTS, embeds, username, avatarUrl, options, isSpoiler).ConfigureAwait(false);
return await SendFileAsync(client, file, filename, text, isTTS, embeds, username, avatarUrl, allowedMentions, options, isSpoiler).ConfigureAwait(false);
}
}
public static async Task<ulong> SendFileAsync(DiscordWebhookClient client, Stream stream, string filename, string text, bool isTTS,
public static async Task<ulong> SendFileAsync(DiscordWebhookClient client, Stream stream, string filename, string text, bool isTTS,
IEnumerable<Embed> embeds, string username, string avatarUrl, RequestOptions options, bool isSpoiler)
IEnumerable<Embed> embeds, string username, string avatarUrl, AllowedMentions allowedMentions, RequestOptions options, bool isSpoiler)
{
{
var args = new UploadWebhookFileParams(stream) { Filename = filename, Content = text, IsTTS = isTTS, IsSpoiler = isSpoiler };
var args = new UploadWebhookFileParams(stream) { Filename = filename, Content = text, IsTTS = isTTS, IsSpoiler = isSpoiler };
if (username != null)
if (username != null)
@@ -51,6 +53,8 @@ namespace Discord.Webhook
args.AvatarUrl = avatarUrl;
args.AvatarUrl = avatarUrl;
if (embeds != null)
if (embeds != null)
args.Embeds = embeds.Select(x => x.ToModel()).ToArray();
args.Embeds = embeds.Select(x => x.ToModel()).ToArray();
if(allowedMentions != null)
args.AllowedMentions = allowedMentions.ToModel();
var msg = await client.ApiClient.UploadWebhookFileAsync(client.Webhook.Id, args, options).ConfigureAwait(false);
var msg = await client.ApiClient.UploadWebhookFileAsync(client.Webhook.Id, args, options).ConfigureAwait(false);
return msg.Id;
return msg.Id;
}
}