@@ -266,8 +266,10 @@ public static async Task<IReadOnlyCollection<RestMessage>> GetPinnedMessagesAsyn
266
266
}
267
267
268
268
/// <exception cref="ArgumentOutOfRangeException">Message content is too long, length must be less or equal to <see cref="DiscordConfig.MaxMessageSize"/>.</exception>
269
+ /// <exception cref="ArgumentException">The only valid <see cref="MessageFlags"/> are <see cref="MessageFlags.SuppressEmbeds"/> and <see cref="MessageFlags.None"/>.</exception>
269
270
public static async Task < RestUserMessage > SendMessageAsync ( IMessageChannel channel , BaseDiscordClient client ,
270
- string text , bool isTTS , Embed embed , AllowedMentions allowedMentions , MessageReference messageReference , MessageComponent components , ISticker [ ] stickers , RequestOptions options , Embed [ ] embeds )
271
+ string text , bool isTTS , Embed embed , AllowedMentions allowedMentions , MessageReference messageReference ,
272
+ MessageComponent components , ISticker [ ] stickers , RequestOptions options , Embed [ ] embeds , MessageFlags flags )
271
273
{
272
274
embeds ??= Array . Empty < Embed > ( ) ;
273
275
if ( embed != null )
@@ -298,14 +300,19 @@ public static async Task<RestUserMessage> SendMessageAsync(IMessageChannel chann
298
300
Preconditions . AtMost ( stickers . Length , 3 , nameof ( stickers ) , "A max of 3 stickers are allowed." ) ;
299
301
}
300
302
303
+
304
+ if ( flags is not MessageFlags . None and not MessageFlags . SuppressEmbeds )
305
+ throw new ArgumentException ( "The only valid MessageFlags are SuppressEmbeds and none." , nameof ( flags ) ) ;
306
+
301
307
var args = new CreateMessageParams ( text )
302
308
{
303
309
IsTTS = isTTS ,
304
310
Embeds = embeds . Any ( ) ? embeds . Select ( x => x . ToModel ( ) ) . ToArray ( ) : Optional < API . Embed [ ] > . Unspecified ,
305
311
AllowedMentions = allowedMentions ? . ToModel ( ) ,
306
312
MessageReference = messageReference ? . ToModel ( ) ,
307
313
Components = components ? . Components . Select ( x => new API . ActionRowComponent ( x ) ) . ToArray ( ) ?? Optional < API . ActionRowComponent [ ] > . Unspecified ,
308
- Stickers = stickers ? . Any ( ) ?? false ? stickers . Select ( x => x . Id ) . ToArray ( ) : Optional < ulong [ ] > . Unspecified
314
+ Stickers = stickers ? . Any ( ) ?? false ? stickers . Select ( x => x . Id ) . ToArray ( ) : Optional < ulong [ ] > . Unspecified ,
315
+ Flags = flags
309
316
} ;
310
317
var model = await client . ApiClient . CreateMessageAsync ( channel . Id , args , options ) . ConfigureAwait ( false ) ;
311
318
return RestUserMessage . Create ( client , channel , client . CurrentUser , model ) ;
@@ -335,29 +342,44 @@ public static async Task<RestUserMessage> SendMessageAsync(IMessageChannel chann
335
342
/// <exception cref="NotSupportedException"><paramref name="filePath" /> is in an invalid format.</exception>
336
343
/// <exception cref="IOException">An I/O error occurred while opening the file.</exception>
337
344
/// <exception cref="ArgumentOutOfRangeException">Message content is too long, length must be less or equal to <see cref="DiscordConfig.MaxMessageSize"/>.</exception>
345
+ /// <exception cref="ArgumentException">The only valid <see cref="MessageFlags"/> are <see cref="MessageFlags.SuppressEmbeds"/> and <see cref="MessageFlags.None"/>.</exception>
338
346
public static async Task < RestUserMessage > SendFileAsync ( IMessageChannel channel , BaseDiscordClient client ,
339
- string filePath , string text , bool isTTS , Embed embed , AllowedMentions allowedMentions , MessageReference messageReference , MessageComponent components , ISticker [ ] stickers , RequestOptions options , bool isSpoiler , Embed [ ] embeds )
347
+ string filePath , string text , bool isTTS , Embed embed , AllowedMentions allowedMentions ,
348
+ MessageReference messageReference , MessageComponent components , ISticker [ ] stickers , RequestOptions options ,
349
+ bool isSpoiler , Embed [ ] embeds , MessageFlags flags = MessageFlags . None )
340
350
{
341
351
string filename = Path . GetFileName ( filePath ) ;
342
352
using ( var file = File . OpenRead ( filePath ) )
343
- return await SendFileAsync ( channel , client , file , filename , text , isTTS , embed , allowedMentions , messageReference , components , stickers , options , isSpoiler , embeds ) . ConfigureAwait ( false ) ;
353
+ return await SendFileAsync ( channel , client , file , filename , text , isTTS , embed , allowedMentions ,
354
+ messageReference , components , stickers , options , isSpoiler , embeds , flags ) . ConfigureAwait ( false ) ;
344
355
}
345
356
346
357
/// <exception cref="ArgumentOutOfRangeException">Message content is too long, length must be less or equal to <see cref="DiscordConfig.MaxMessageSize"/>.</exception>
358
+ /// <exception cref="ArgumentException">The only valid <see cref="MessageFlags"/> are <see cref="MessageFlags.SuppressEmbeds"/> and <see cref="MessageFlags.None"/>.</exception>
347
359
public static async Task < RestUserMessage > SendFileAsync ( IMessageChannel channel , BaseDiscordClient client ,
348
- Stream stream , string filename , string text , bool isTTS , Embed embed , AllowedMentions allowedMentions , MessageReference messageReference , MessageComponent components , ISticker [ ] stickers , RequestOptions options , bool isSpoiler , Embed [ ] embeds )
360
+ Stream stream , string filename , string text , bool isTTS , Embed embed , AllowedMentions allowedMentions ,
361
+ MessageReference messageReference , MessageComponent components , ISticker [ ] stickers , RequestOptions options ,
362
+ bool isSpoiler , Embed [ ] embeds , MessageFlags flags = MessageFlags . None )
349
363
{
350
364
using ( var file = new FileAttachment ( stream , filename , isSpoiler : isSpoiler ) )
351
- return await SendFileAsync ( channel , client , file , text , isTTS , embed , allowedMentions , messageReference , components , stickers , options , embeds ) . ConfigureAwait ( false ) ;
365
+ return await SendFileAsync ( channel , client , file , text , isTTS , embed , allowedMentions , messageReference ,
366
+ components , stickers , options , embeds , flags ) . ConfigureAwait ( false ) ;
352
367
}
353
368
354
369
/// <exception cref="ArgumentOutOfRangeException">Message content is too long, length must be less or equal to <see cref="DiscordConfig.MaxMessageSize"/>.</exception>
370
+ /// <exception cref="ArgumentException">The only valid <see cref="MessageFlags"/> are <see cref="MessageFlags.SuppressEmbeds"/> and <see cref="MessageFlags.None"/>.</exception>
355
371
public static Task < RestUserMessage > SendFileAsync ( IMessageChannel channel , BaseDiscordClient client ,
356
- FileAttachment attachment , string text , bool isTTS , Embed embed , AllowedMentions allowedMentions , MessageReference messageReference , MessageComponent components , ISticker [ ] stickers , RequestOptions options , Embed [ ] embeds )
357
- => SendFilesAsync ( channel , client , new [ ] { attachment } , text , isTTS , embed , allowedMentions , messageReference , components , stickers , options , embeds ) ;
372
+ FileAttachment attachment , string text , bool isTTS , Embed embed , AllowedMentions allowedMentions ,
373
+ MessageReference messageReference , MessageComponent components , ISticker [ ] stickers , RequestOptions options ,
374
+ Embed [ ] embeds , MessageFlags flags = MessageFlags . None )
375
+ => SendFilesAsync ( channel , client , new [ ] { attachment } , text , isTTS , embed , allowedMentions , messageReference ,
376
+ components , stickers , options , embeds , flags ) ;
358
377
378
+ /// <exception cref="ArgumentException">The only valid <see cref="MessageFlags"/> are <see cref="MessageFlags.SuppressEmbeds"/> and <see cref="MessageFlags.None"/>.</exception>
359
379
public static async Task < RestUserMessage > SendFilesAsync ( IMessageChannel channel , BaseDiscordClient client ,
360
- IEnumerable < FileAttachment > attachments , string text , bool isTTS , Embed embed , AllowedMentions allowedMentions , MessageReference messageReference , MessageComponent components , ISticker [ ] stickers , RequestOptions options , Embed [ ] embeds )
380
+ IEnumerable < FileAttachment > attachments , string text , bool isTTS , Embed embed , AllowedMentions allowedMentions ,
381
+ MessageReference messageReference , MessageComponent components , ISticker [ ] stickers , RequestOptions options ,
382
+ Embed [ ] embeds , MessageFlags flags )
361
383
{
362
384
embeds ??= Array . Empty < Embed > ( ) ;
363
385
if ( embed != null )
@@ -366,7 +388,7 @@ public static async Task<RestUserMessage> SendFilesAsync(IMessageChannel channel
366
388
Preconditions . AtMost ( allowedMentions ? . RoleIds ? . Count ?? 0 , 100 , nameof ( allowedMentions . RoleIds ) , "A max of 100 role Ids are allowed." ) ;
367
389
Preconditions . AtMost ( allowedMentions ? . UserIds ? . Count ?? 0 , 100 , nameof ( allowedMentions . UserIds ) , "A max of 100 user Ids are allowed." ) ;
368
390
Preconditions . AtMost ( embeds . Length , 10 , nameof ( embeds ) , "A max of 10 embeds are allowed." ) ;
369
-
391
+
370
392
foreach ( var attachment in attachments )
371
393
{
372
394
Preconditions . NotNullOrEmpty ( attachment . FileName , nameof ( attachment . FileName ) , "File Name must not be empty or null" ) ;
@@ -398,12 +420,26 @@ public static async Task<RestUserMessage> SendFilesAsync(IMessageChannel channel
398
420
}
399
421
}
400
422
423
+ if ( flags is not MessageFlags . None and not MessageFlags . SuppressEmbeds )
424
+ throw new ArgumentException ( "The only valid MessageFlags are SuppressEmbeds and none." , nameof ( flags ) ) ;
425
+
401
426
if ( stickers != null )
402
427
{
403
428
Preconditions . AtMost ( stickers . Length , 3 , nameof ( stickers ) , "A max of 3 stickers are allowed." ) ;
404
429
}
405
430
406
- var args = new UploadFileParams ( attachments . ToArray ( ) ) { Content = text , IsTTS = isTTS , Embeds = embeds . Any ( ) ? embeds . Select ( x => x . ToModel ( ) ) . ToArray ( ) : Optional < API . Embed [ ] > . Unspecified , AllowedMentions = allowedMentions ? . ToModel ( ) ?? Optional < API . AllowedMentions > . Unspecified , MessageReference = messageReference ? . ToModel ( ) ?? Optional < API . MessageReference > . Unspecified , MessageComponent = components ? . Components . Select ( x => new API . ActionRowComponent ( x ) ) . ToArray ( ) ?? Optional < API . ActionRowComponent [ ] > . Unspecified , Stickers = stickers ? . Any ( ) ?? false ? stickers . Select ( x => x . Id ) . ToArray ( ) : Optional < ulong [ ] > . Unspecified } ;
431
+ var args = new UploadFileParams ( attachments . ToArray ( ) )
432
+ {
433
+ Content = text ,
434
+ IsTTS = isTTS ,
435
+ Embeds = embeds . Any ( ) ? embeds . Select ( x => x . ToModel ( ) ) . ToArray ( ) : Optional < API . Embed [ ] > . Unspecified ,
436
+ AllowedMentions = allowedMentions ? . ToModel ( ) ?? Optional < API . AllowedMentions > . Unspecified ,
437
+ MessageReference = messageReference ? . ToModel ( ) ?? Optional < API . MessageReference > . Unspecified ,
438
+ MessageComponent = components ? . Components . Select ( x => new API . ActionRowComponent ( x ) ) . ToArray ( ) ?? Optional < API . ActionRowComponent [ ] > . Unspecified ,
439
+ Stickers = stickers ? . Any ( ) ?? false ? stickers . Select ( x => x . Id ) . ToArray ( ) : Optional < ulong [ ] > . Unspecified ,
440
+ Flags = flags
441
+ } ;
442
+
407
443
var model = await client . ApiClient . UploadFileAsync ( channel . Id , args , options ) . ConfigureAwait ( false ) ;
408
444
return RestUserMessage . Create ( client , channel , client . CurrentUser , model ) ;
409
445
}
0 commit comments