async Task <IUserMessage> IMessageChannel.SendInteractionFileAsync(InteractionData interaction, Stream stream, string filename, string text, bool isTTS, Embed embed, RequestOptions options, bool isSpoiler, AllowedMentions allowedMentions, MessageReferenceParams reference, InteractionMessageType type, bool ghostMessage, InteractionRow[] components) => await SendInteractionFileAsync(interaction, stream, filename, text, isTTS, embed, options, isSpoiler, allowedMentions, reference, type, ghostMessage, components).ConfigureAwait(false);
/// <inheritdoc /> /// <exception cref="ArgumentOutOfRangeException">Message content is too long, length must be less or equal to <see cref="DiscordConfig.MaxMessageSize"/>.</exception> public Task <RestUserMessage> SendInteractionFileAsync(InteractionData interaction, Stream stream, string filename, string text = null, bool isTTS = false, Embed embed = null, RequestOptions options = null, bool isSpoiler = false, AllowedMentions allowedMentions = null, MessageReferenceParams reference = null, InteractionMessageType type = InteractionMessageType.ChannelMessageWithSource, bool ghostMessage = false, InteractionRow[] components = null) => ChannelHelper.SendInteractionFileAsync(this, Discord, interaction, stream, filename, text, isTTS, embed, allowedMentions, options, isSpoiler, reference, type, ghostMessage, components);
public static async Task <RestUserMessage> SendInteractionFileAsync(IMessageChannel channel, BaseDiscordClient client, InteractionData interaction, string filePath, string text, bool isTTS, Embed embed, AllowedMentions allowedMentions, RequestOptions options, bool isSpoiler, MessageReferenceParams reference, InteractionMessageType type, bool ghostMessage, InteractionRow[] components) { string filename = Path.GetFileName(filePath); using (FileStream file = File.OpenRead(filePath)) return(await SendInteractionFileAsync(channel, client, interaction, file, filename, text, isTTS, embed, allowedMentions, options, isSpoiler, reference, type, ghostMessage, components).ConfigureAwait(false)); }
public static async Task <RestUserMessage> SendInteractionFileAsync(IMessageChannel channel, BaseDiscordClient client, InteractionData interaction, Stream stream, string filename, string text, bool isTTS, Embed embed, AllowedMentions allowedMentions, RequestOptions options, bool isSpoiler, MessageReferenceParams reference, InteractionMessageType type, bool ghostMessage, InteractionRow[] components) { if (interaction == null) { return(await SendFileAsync(channel, client, stream, filename, text, isTTS, embed, allowedMentions, options, isSpoiler, reference, components).ConfigureAwait(false)); } Preconditions.AtMost(allowedMentions?.RoleIds?.Count ?? 0, 100, nameof(allowedMentions.RoleIds), "A max of 100 role Ids are allowed."); Preconditions.AtMost(allowedMentions?.UserIds?.Count ?? 0, 100, nameof(allowedMentions.UserIds), "A max of 100 user Ids are allowed."); // check that user flag and user Id list are exclusive, same with role flag and role Id list if (allowedMentions != null && allowedMentions.AllowedTypes.HasValue) { if (allowedMentions.AllowedTypes.Value.HasFlag(AllowedMentionTypes.Users) && allowedMentions.UserIds != null && allowedMentions.UserIds.Count > 0) { throw new ArgumentException("The Users flag is mutually exclusive with the list of User Ids.", nameof(allowedMentions)); } if (allowedMentions.AllowedTypes.Value.HasFlag(AllowedMentionTypes.Roles) && allowedMentions.RoleIds != null && allowedMentions.RoleIds.Count > 0) { throw new ArgumentException("The Roles flag is mutually exclusive with the list of Role Ids.", nameof(allowedMentions)); } } UploadInteractionFileParams args = new UploadInteractionFileParams { Type = type, Data = new UploadWebhookFileParams(stream) { Filename = filename, Content = text, IsTTS = isTTS, AllowedMentions = allowedMentions?.ToModel() ?? Optional <API.AllowedMentions> .Unspecified, IsSpoiler = isSpoiler, Components = components?.Select(x => x.ToModel()).ToArray() } }; if (embed != null) { args.Data.Embeds = new API.EmbedJson[] { embed.ToModel() } } ; if (ghostMessage) { args.Data.Flags = 64; } API.MessageJson model = await client.ApiClient.UploadInteractionFileAsync(channel.Id, interaction, args, options).ConfigureAwait(false); return(RestUserMessage.Create(client, channel, client.CurrentUser, model)); }
public static async Task <RestUserMessage> SendInteractionMessageAsync(IMessageChannel channel, BaseDiscordClient client, InteractionData interaction, string text, bool isTTS, Embed embed, AllowedMentions allowedMentions, MessageReferenceParams reference, RequestOptions options, InteractionMessageType type, bool ghostMessage, InteractionRow[] components) { if (interaction == null) { return(await SendMessageAsync(channel, client, text, isTTS, embed, allowedMentions, reference, options, components).ConfigureAwait(false)); } Preconditions.AtMost(allowedMentions?.RoleIds?.Count ?? 0, 100, nameof(allowedMentions.RoleIds), "A max of 100 role Ids are allowed."); Preconditions.AtMost(allowedMentions?.UserIds?.Count ?? 0, 100, nameof(allowedMentions.UserIds), "A max of 100 user Ids are allowed."); // check that user flag and user Id list are exclusive, same with role flag and role Id list if (allowedMentions != null && allowedMentions.AllowedTypes.HasValue) { if (allowedMentions.AllowedTypes.Value.HasFlag(AllowedMentionTypes.Users) && allowedMentions.UserIds != null && allowedMentions.UserIds.Count > 0) { throw new ArgumentException("The Users flag is mutually exclusive with the list of User Ids.", nameof(allowedMentions)); } if (allowedMentions.AllowedTypes.Value.HasFlag(AllowedMentionTypes.Roles) && allowedMentions.RoleIds != null && allowedMentions.RoleIds.Count > 0) { throw new ArgumentException("The Roles flag is mutually exclusive with the list of Role Ids.", nameof(allowedMentions)); } } CreateInteractionMessageParams args = new CreateInteractionMessageParams() { Type = type }; switch (type) { case InteractionMessageType.ChannelMessageWithSource: args.Data = new CreateWebhookMessageParams(text) { IsTTS = isTTS, AllowedMentions = allowedMentions?.ToModel() }; break; } if (components != null) { args.Data.Components = components?.Select(x => x.ToModel()).ToArray(); } if (embed != null) { args.Data.Embeds = new API.EmbedJson[] { embed.ToModel() } } ; if (ghostMessage) { args.Data.Flags = 64; } API.MessageJson model = await client.ApiClient.CreateInteractionMessageAsync(channel.Id, interaction, args, options).ConfigureAwait(false); if (model == null) { return(null); } return(RestUserMessage.Create(client, channel, client.CurrentUser, model)); }