diff --git a/src/Discord.Net.Core/Entities/Channels/IStageChannel.cs b/src/Discord.Net.Core/Entities/Channels/IStageChannel.cs
index 9c6d9e187..935acaab9 100644
--- a/src/Discord.Net.Core/Entities/Channels/IStageChannel.cs
+++ b/src/Discord.Net.Core/Entities/Channels/IStageChannel.cs
@@ -1,7 +1,4 @@
using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
using System.Threading.Tasks;
namespace Discord
diff --git a/src/Discord.Net.Core/Entities/Channels/IThreadChannel.cs b/src/Discord.Net.Core/Entities/Channels/IThreadChannel.cs
index dfafb313d..570cdaa2f 100644
--- a/src/Discord.Net.Core/Entities/Channels/IThreadChannel.cs
+++ b/src/Discord.Net.Core/Entities/Channels/IThreadChannel.cs
@@ -1,7 +1,4 @@
using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
using System.Threading.Tasks;
namespace Discord
@@ -9,7 +6,7 @@ namespace Discord
///
/// Represents a thread channel inside of a guild.
///
- public interface IThreadChannel : ITextChannel, IGuildChannel
+ public interface IThreadChannel : ITextChannel
{
///
/// Gets the type of the current thread channel.
@@ -56,7 +53,7 @@ namespace Discord
///
/// The options to be used when sending the request.
///
- /// A task that represents the asynchronous join operation.
+ /// A task that represents the asynchronous join operation.
///
Task JoinAsync(RequestOptions options = null);
@@ -65,7 +62,7 @@ namespace Discord
///
/// The options to be used when sending the request.
///
- /// A task that represents the asynchronous leave operation.
+ /// A task that represents the asynchronous leave operation.
///
Task LeaveAsync(RequestOptions options = null);
@@ -75,7 +72,7 @@ namespace Discord
/// The to add.
/// The options to be used when sending the request.
///
- /// A task that represents the asynchronous operation of adding a member to a thread.
+ /// A task that represents the asynchronous operation of adding a member to a thread.
///
Task AddUserAsync(IGuildUser user, RequestOptions options = null);
@@ -85,7 +82,7 @@ namespace Discord
/// The to remove from this thread.
/// The options to be used when sending the request.
///
- /// A task that represents the asynchronous operation of removing a user from this thread.
+ /// A task that represents the asynchronous operation of removing a user from this thread.
///
Task RemoveUserAsync(IGuildUser user, RequestOptions options = null);
}
diff --git a/src/Discord.Net.Core/Entities/Channels/StageInstanceProperties.cs b/src/Discord.Net.Core/Entities/Channels/StageInstanceProperties.cs
index ad539adc3..35201fe0f 100644
--- a/src/Discord.Net.Core/Entities/Channels/StageInstanceProperties.cs
+++ b/src/Discord.Net.Core/Entities/Channels/StageInstanceProperties.cs
@@ -1,9 +1,3 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
namespace Discord
{
///
diff --git a/src/Discord.Net.Core/Entities/Channels/StagePrivacyLevel.cs b/src/Discord.Net.Core/Entities/Channels/StagePrivacyLevel.cs
index 6a51ab4ac..9d55e713d 100644
--- a/src/Discord.Net.Core/Entities/Channels/StagePrivacyLevel.cs
+++ b/src/Discord.Net.Core/Entities/Channels/StagePrivacyLevel.cs
@@ -1,14 +1,17 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
namespace Discord
{
+ ///
+ /// Specifies the privacy levels of a Stage instance.
+ ///
public enum StagePrivacyLevel
{
+ ///
+ /// The Stage instance is visible publicly, such as on Stage Discovery.
+ ///
Public = 1,
- GuildOnly = 2,
+ ///
+ /// The Stage instance is visible to only guild members.
+ ///
+ GuildOnly = 2
}
}
diff --git a/src/Discord.Net.Core/Entities/Channels/ThreadArchiveDuration.cs b/src/Discord.Net.Core/Entities/Channels/ThreadArchiveDuration.cs
index 01d1574bf..2c8a0652c 100644
--- a/src/Discord.Net.Core/Entities/Channels/ThreadArchiveDuration.cs
+++ b/src/Discord.Net.Core/Entities/Channels/ThreadArchiveDuration.cs
@@ -1,9 +1,3 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
namespace Discord
{
///
@@ -24,7 +18,7 @@ namespace Discord
///
/// Three days (4320 minutes).
///
- /// This option is explicity avaliable to nitro users.
+ /// This option is explicitly available to nitro users.
///
///
ThreeDays = 4320,
@@ -32,9 +26,9 @@ namespace Discord
///
/// One week (10080 minutes).
///
- /// This option is explicity avaliable to nitro users.
+ /// This option is explicitly available to nitro users.
///
///
- OneWeek = 10080,
+ OneWeek = 10080
}
}
diff --git a/src/Discord.Net.Core/Entities/Channels/ThreadType.cs b/src/Discord.Net.Core/Entities/Channels/ThreadType.cs
index 2db09bcb9..379128d21 100644
--- a/src/Discord.Net.Core/Entities/Channels/ThreadType.cs
+++ b/src/Discord.Net.Core/Entities/Channels/ThreadType.cs
@@ -1,9 +1,3 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
namespace Discord
{
///
@@ -24,6 +18,6 @@ namespace Discord
///
/// Represents a temporary sub-channel within a GUILD_TEXT channel that is only viewable by those invited and those with the MANAGE_THREADS permission
///
- PrivateThread = 12,
+ PrivateThread = 12
}
}
diff --git a/src/Discord.Net.Core/Entities/Interactions/ApplicationCommandOption.cs b/src/Discord.Net.Core/Entities/Interactions/ApplicationCommandOption.cs
index 5b5353999..828847791 100644
--- a/src/Discord.Net.Core/Entities/Interactions/ApplicationCommandOption.cs
+++ b/src/Discord.Net.Core/Entities/Interactions/ApplicationCommandOption.cs
@@ -1,9 +1,6 @@
using System;
using System.Collections.Generic;
-using System.Linq;
-using System.Text;
using System.Text.RegularExpressions;
-using System.Threading.Tasks;
namespace Discord
{
@@ -24,13 +21,13 @@ namespace Discord
set
{
if (value == null)
- throw new ArgumentNullException($"{nameof(Name)} cannot be null!");
+ throw new ArgumentNullException(nameof(value), $"{nameof(Name)} cannot be null.");
if (value.Length > 32)
- throw new ArgumentException($"{nameof(Name)} length must be less than or equal to 32");
+ throw new ArgumentOutOfRangeException(nameof(value), "Name length must be less than or equal to 32.");
if (!Regex.IsMatch(value, @"^[\w-]{1,32}$"))
- throw new ArgumentException($"{nameof(Name)} must match the regex ^[\\w-]{{1,32}}$");
+ throw new FormatException($"{nameof(value)} must match the regex ^[\\w-]{{1,32}}$");
_name = value;
}
@@ -42,14 +39,12 @@ namespace Discord
public string Description
{
get => _description;
- set
+ set => _description = value?.Length switch
{
- if (value?.Length > 100)
- throw new ArgumentException("Description length must be less than or equal to 100");
- if (value?.Length < 1)
- throw new ArgumentException("Description length must at least 1 character in length");
- _description = value;
- }
+ > 100 => throw new ArgumentOutOfRangeException(nameof(value), "Description length must be less than or equal to 100."),
+ 0 => throw new ArgumentOutOfRangeException(nameof(value), "Description length must be at least 1."),
+ _ => value
+ };
}
///
diff --git a/src/Discord.Net.Core/Entities/Interactions/ApplicationCommandOptionChoice.cs b/src/Discord.Net.Core/Entities/Interactions/ApplicationCommandOptionChoice.cs
index 4a1339dc2..8b8b5a3aa 100644
--- a/src/Discord.Net.Core/Entities/Interactions/ApplicationCommandOptionChoice.cs
+++ b/src/Discord.Net.Core/Entities/Interactions/ApplicationCommandOptionChoice.cs
@@ -1,8 +1,4 @@
using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
namespace Discord
{
@@ -19,14 +15,12 @@ namespace Discord
public string Name
{
get => _name;
- set
+ set => _name = value?.Length switch
{
- if(value?.Length > 100)
- throw new ArgumentException("Name length must be less than or equal to 100");
- if (value?.Length < 1)
- throw new ArgumentException("Name length must at least 1 character in length");
- _name = value;
- }
+ > 100 => throw new ArgumentOutOfRangeException(nameof(value), "Name length must be less than or equal to 100."),
+ 0 => throw new ArgumentOutOfRangeException(nameof(value), "Name length must at least 1."),
+ _ => value
+ };
}
///
@@ -40,11 +34,8 @@ namespace Discord
get => _value;
set
{
- if(value != null)
- {
- if(!(value is int) && !(value is string))
- throw new ArgumentException("The value of a choice must be a string or int!");
- }
+ if (value != null && value is not int && value is not string)
+ throw new ArgumentException("The value of a choice must be a string or int!");
_value = value;
}
}
diff --git a/src/Discord.Net.Core/Entities/Interactions/ApplicationCommandOptionType.cs b/src/Discord.Net.Core/Entities/Interactions/ApplicationCommandOptionType.cs
index a1b366e18..0f919f1f6 100644
--- a/src/Discord.Net.Core/Entities/Interactions/ApplicationCommandOptionType.cs
+++ b/src/Discord.Net.Core/Entities/Interactions/ApplicationCommandOptionType.cs
@@ -1,9 +1,3 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
namespace Discord
{
///
@@ -37,7 +31,7 @@ namespace Discord
Boolean = 5,
///
- /// A .
+ /// A .
///
User = 6,
@@ -55,7 +49,7 @@ namespace Discord
/// A or .
///
Mentionable = 9,
-
+
///
/// A .
///
diff --git a/src/Discord.Net.Core/Entities/Interactions/ApplicationCommandProperties.cs b/src/Discord.Net.Core/Entities/Interactions/ApplicationCommandProperties.cs
index 55c91bc64..25ef212c5 100644
--- a/src/Discord.Net.Core/Entities/Interactions/ApplicationCommandProperties.cs
+++ b/src/Discord.Net.Core/Entities/Interactions/ApplicationCommandProperties.cs
@@ -1,9 +1,3 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
namespace Discord
{
///
diff --git a/src/Discord.Net.Core/Entities/Interactions/ApplicationCommandTypes.cs b/src/Discord.Net.Core/Entities/Interactions/ApplicationCommandTypes.cs
index 3cfa97a5a..b6804deee 100644
--- a/src/Discord.Net.Core/Entities/Interactions/ApplicationCommandTypes.cs
+++ b/src/Discord.Net.Core/Entities/Interactions/ApplicationCommandTypes.cs
@@ -1,9 +1,3 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
namespace Discord
{
///
diff --git a/src/Discord.Net.Core/Entities/Interactions/AutocompleteOption.cs b/src/Discord.Net.Core/Entities/Interactions/AutocompleteOption.cs
index 2a97a7295..4f7d3cb5f 100644
--- a/src/Discord.Net.Core/Entities/Interactions/AutocompleteOption.cs
+++ b/src/Discord.Net.Core/Entities/Interactions/AutocompleteOption.cs
@@ -1,9 +1,3 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
namespace Discord
{
///
diff --git a/src/Discord.Net.Core/Entities/Interactions/AutocompleteResult.cs b/src/Discord.Net.Core/Entities/Interactions/AutocompleteResult.cs
index a0992fd00..a4333ceb2 100644
--- a/src/Discord.Net.Core/Entities/Interactions/AutocompleteResult.cs
+++ b/src/Discord.Net.Core/Entities/Interactions/AutocompleteResult.cs
@@ -1,8 +1,4 @@
using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
namespace Discord
{
@@ -11,8 +7,8 @@ namespace Discord
///
public class AutocompleteResult
{
- private object _value { get; set; }
- private string _name { get; set; }
+ private object _value;
+ private string _name;
///
/// Gets or sets the name of the result.
@@ -28,12 +24,13 @@ namespace Discord
set
{
if (value == null)
- throw new ArgumentException("Name cannot be null!");
- if (value.Length > 100)
- throw new ArgumentException("Name length must be less than or equal to 100 characters in length!");
- if (value.Length < 1)
- throw new ArgumentException("Name length must at least 1 character in length!");
- _name = value;
+ throw new ArgumentNullException(nameof(value), $"{nameof(Name)} cannot be null.");
+ _name = value.Length switch
+ {
+ > 100 => throw new ArgumentOutOfRangeException(nameof(value), "Name length must be less than or equal to 100."),
+ 0 => throw new ArgumentOutOfRangeException(nameof(value), "Name length must be at least 1."),
+ _ => value
+ };
}
}
@@ -48,20 +45,15 @@ namespace Discord
public object Value
{
get => _value;
- set
+ set => _value = value switch
{
- if (value == null)
- throw new ArgumentNullException("Value cannot be null");
-
- _value = value switch
- {
- string str => str,
- int integer => integer,
- long lng => lng,
- double number => number,
- _ => throw new ArgumentException($"Type {value.GetType().Name} cannot be set as a value! Only string, int, and double allowed!"),
- };
- }
+ string str => str,
+ int integer => integer,
+ long lng => lng,
+ double number => number,
+ null => throw new ArgumentNullException(nameof(value), $"{nameof(Value)} cannot be null."),
+ _ => throw new ArgumentException($"Type {value.GetType().Name} cannot be set as a value! Only string, int, and double allowed!")
+ };
}
///
diff --git a/src/Discord.Net.Core/Entities/Interactions/Context Menus/MessageCommandBuilder.cs b/src/Discord.Net.Core/Entities/Interactions/Context Menus/MessageCommandBuilder.cs
index 07d8bcfbf..61b599fcd 100644
--- a/src/Discord.Net.Core/Entities/Interactions/Context Menus/MessageCommandBuilder.cs
+++ b/src/Discord.Net.Core/Entities/Interactions/Context Menus/MessageCommandBuilder.cs
@@ -1,10 +1,3 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Text.RegularExpressions;
-using System.Threading.Tasks;
-
namespace Discord
{
///
@@ -12,7 +5,7 @@ namespace Discord
///
public class MessageCommandBuilder
{
- ///
+ ///
/// Returns the maximum length a commands name allowed by Discord
///
public const int MaxNameLength = 32;
@@ -22,10 +15,7 @@ namespace Discord
///
public string Name
{
- get
- {
- return _name;
- }
+ get => _name;
set
{
Preconditions.NotNullOrEmpty(value, nameof(Name));
@@ -41,7 +31,7 @@ namespace Discord
///
public bool IsDefaultPermission { get; set; } = true;
- private string _name { get; set; }
+ private string _name;
///
/// Build the current builder into a class.
@@ -51,14 +41,13 @@ namespace Discord
///
public MessageCommandProperties Build()
{
- MessageCommandProperties props = new MessageCommandProperties()
+ var props = new MessageCommandProperties
{
Name = Name,
DefaultPermission = IsDefaultPermission
};
return props;
-
}
///
@@ -79,7 +68,7 @@ namespace Discord
///
/// The default permission value to set.
/// The current builder.
- public MessageCommandBuilder WithDefaultPermission (bool isDefaultPermission)
+ public MessageCommandBuilder WithDefaultPermission(bool isDefaultPermission)
{
IsDefaultPermission = isDefaultPermission;
return this;
diff --git a/src/Discord.Net.Core/Entities/Interactions/Context Menus/MessageCommandProperties.cs b/src/Discord.Net.Core/Entities/Interactions/Context Menus/MessageCommandProperties.cs
index 3af9b47f3..356ed23d6 100644
--- a/src/Discord.Net.Core/Entities/Interactions/Context Menus/MessageCommandProperties.cs
+++ b/src/Discord.Net.Core/Entities/Interactions/Context Menus/MessageCommandProperties.cs
@@ -1,9 +1,3 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
namespace Discord
{
///
diff --git a/src/Discord.Net.Core/Entities/Interactions/Context Menus/UserCommandBuilder.cs b/src/Discord.Net.Core/Entities/Interactions/Context Menus/UserCommandBuilder.cs
index 2cc0da4bd..67bd5ad48 100644
--- a/src/Discord.Net.Core/Entities/Interactions/Context Menus/UserCommandBuilder.cs
+++ b/src/Discord.Net.Core/Entities/Interactions/Context Menus/UserCommandBuilder.cs
@@ -1,10 +1,3 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Text.RegularExpressions;
-using System.Threading.Tasks;
-
namespace Discord
{
///
@@ -22,10 +15,7 @@ namespace Discord
///
public string Name
{
- get
- {
- return _name;
- }
+ get => _name;
set
{
Preconditions.NotNullOrEmpty(value, nameof(Name));
@@ -41,7 +31,7 @@ namespace Discord
///
public bool IsDefaultPermission { get; set; } = true;
- private string _name { get; set; }
+ private string _name;
///
/// Build the current builder into a class.
@@ -49,14 +39,13 @@ namespace Discord
/// A that can be used to create user commands.
public UserCommandProperties Build()
{
- UserCommandProperties props = new UserCommandProperties()
+ var props = new UserCommandProperties
{
Name = Name,
DefaultPermission = IsDefaultPermission
};
return props;
-
}
///
@@ -77,7 +66,7 @@ namespace Discord
///
/// The default permission value to set.
/// The current builder.
- public UserCommandBuilder WithDefaultPermission (bool isDefaultPermission)
+ public UserCommandBuilder WithDefaultPermission(bool isDefaultPermission)
{
IsDefaultPermission = isDefaultPermission;
return this;
diff --git a/src/Discord.Net.Core/Entities/Interactions/Context Menus/UserCommandProperties.cs b/src/Discord.Net.Core/Entities/Interactions/Context Menus/UserCommandProperties.cs
index 091166a17..c42e916d9 100644
--- a/src/Discord.Net.Core/Entities/Interactions/Context Menus/UserCommandProperties.cs
+++ b/src/Discord.Net.Core/Entities/Interactions/Context Menus/UserCommandProperties.cs
@@ -1,9 +1,3 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
namespace Discord
{
///
diff --git a/src/Discord.Net.Core/Entities/Interactions/IApplicationCommand.cs b/src/Discord.Net.Core/Entities/Interactions/IApplicationCommand.cs
index 3fe53b72c..faf724cd2 100644
--- a/src/Discord.Net.Core/Entities/Interactions/IApplicationCommand.cs
+++ b/src/Discord.Net.Core/Entities/Interactions/IApplicationCommand.cs
@@ -1,7 +1,5 @@
using System;
using System.Collections.Generic;
-using System.Linq;
-using System.Text;
using System.Threading.Tasks;
namespace Discord
@@ -17,7 +15,7 @@ namespace Discord
ulong ApplicationId { get; }
///
- /// The type of the command
+ /// The type of the command.
///
ApplicationCommandType Type { get; }
diff --git a/src/Discord.Net.Core/Entities/Interactions/IApplicationCommandInteractionData.cs b/src/Discord.Net.Core/Entities/Interactions/IApplicationCommandInteractionData.cs
index ec452180a..c74eba8bb 100644
--- a/src/Discord.Net.Core/Entities/Interactions/IApplicationCommandInteractionData.cs
+++ b/src/Discord.Net.Core/Entities/Interactions/IApplicationCommandInteractionData.cs
@@ -1,8 +1,4 @@
-using System;
using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
namespace Discord
{
diff --git a/src/Discord.Net.Core/Entities/Interactions/IApplicationCommandInteractionDataOption.cs b/src/Discord.Net.Core/Entities/Interactions/IApplicationCommandInteractionDataOption.cs
index 999309979..28e37fbb6 100644
--- a/src/Discord.Net.Core/Entities/Interactions/IApplicationCommandInteractionDataOption.cs
+++ b/src/Discord.Net.Core/Entities/Interactions/IApplicationCommandInteractionDataOption.cs
@@ -1,8 +1,4 @@
-using System;
using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
namespace Discord
{
@@ -33,6 +29,5 @@ namespace Discord
/// Present if this option is a group or subcommand.
///
IReadOnlyCollection Options { get; }
-
}
}
diff --git a/src/Discord.Net.Core/Entities/Interactions/IApplicationCommandOption.cs b/src/Discord.Net.Core/Entities/Interactions/IApplicationCommandOption.cs
index 39bf5418f..a76abc68e 100644
--- a/src/Discord.Net.Core/Entities/Interactions/IApplicationCommandOption.cs
+++ b/src/Discord.Net.Core/Entities/Interactions/IApplicationCommandOption.cs
@@ -1,8 +1,4 @@
-using System;
using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
namespace Discord
{
@@ -39,16 +35,16 @@ namespace Discord
///
/// Choices for string and int types for the user to pick from.
///
- IReadOnlyCollection? Choices { get; }
+ IReadOnlyCollection Choices { get; }
///
/// If the option is a subcommand or subcommand group type, this nested options will be the parameters.
///
- IReadOnlyCollection? Options { get; }
+ IReadOnlyCollection Options { get; }
///
/// The allowed channel types for this option.
///
- IReadOnlyCollection? ChannelTypes { get; }
+ IReadOnlyCollection ChannelTypes { get; }
}
}
diff --git a/src/Discord.Net.Core/Entities/Interactions/IApplicationCommandOptionChoice.cs b/src/Discord.Net.Core/Entities/Interactions/IApplicationCommandOptionChoice.cs
index 1f0540656..ac03eb37c 100644
--- a/src/Discord.Net.Core/Entities/Interactions/IApplicationCommandOptionChoice.cs
+++ b/src/Discord.Net.Core/Entities/Interactions/IApplicationCommandOptionChoice.cs
@@ -1,9 +1,3 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
namespace Discord
{
///
@@ -20,6 +14,5 @@ namespace Discord
/// value of the choice.
///
object Value { get; }
-
}
}
diff --git a/src/Discord.Net.Core/Entities/Interactions/IDiscordInteraction.cs b/src/Discord.Net.Core/Entities/Interactions/IDiscordInteraction.cs
index 572e52a7e..925ae08fc 100644
--- a/src/Discord.Net.Core/Entities/Interactions/IDiscordInteraction.cs
+++ b/src/Discord.Net.Core/Entities/Interactions/IDiscordInteraction.cs
@@ -1,7 +1,4 @@
using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
using System.Threading.Tasks;
namespace Discord
@@ -51,7 +48,7 @@ namespace Discord
/// The request options for this response.
/// A to be sent with this response.
/// A single embed to send with this response. If this is passed alongside an array of embeds, the single embed will be ignored.
- Task RespondAsync (string text = null, Embed[] embeds = null, bool isTTS = false,
+ Task RespondAsync(string text = null, Embed[] embeds = null, bool isTTS = false,
bool ephemeral = false, AllowedMentions allowedMentions = null, RequestOptions options = null, MessageComponent component = null, Embed embed = null);
///
@@ -68,7 +65,7 @@ namespace Discord
///
/// The sent message.
///
- Task FollowupAsync (string text = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false,
+ Task FollowupAsync(string text = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false,
AllowedMentions allowedMentions = null, RequestOptions options = null, MessageComponent component = null, Embed embed = null);
///
@@ -76,7 +73,7 @@ namespace Discord
///
/// The request options for this request.
/// A that represents the initial response.
- Task GetOriginalResponseAsync (RequestOptions options = null);
+ Task GetOriginalResponseAsync(RequestOptions options = null);
///
/// Edits original response for this interaction.
@@ -84,7 +81,7 @@ namespace Discord
/// A delegate containing the properties to modify the message with.
/// The request options for this request.
/// A that represents the initial response.
- Task ModifyOriginalResponseAsync (Action func, RequestOptions options = null);
+ Task ModifyOriginalResponseAsync(Action func, RequestOptions options = null);
///
/// Acknowledges this interaction.
@@ -92,6 +89,6 @@ namespace Discord
///
/// A task that represents the asynchronous operation of acknowledging the interaction.
///
- Task DeferAsync (bool ephemeral = false, RequestOptions options = null);
+ Task DeferAsync(bool ephemeral = false, RequestOptions options = null);
}
}
diff --git a/src/Discord.Net.Core/Entities/Interactions/IDiscordInteractionData.cs b/src/Discord.Net.Core/Entities/Interactions/IDiscordInteractionData.cs
index f55b46869..42b95738e 100644
--- a/src/Discord.Net.Core/Entities/Interactions/IDiscordInteractionData.cs
+++ b/src/Discord.Net.Core/Entities/Interactions/IDiscordInteractionData.cs
@@ -1,13 +1,7 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
namespace Discord
{
///
- /// Represents an interface used to specify classes that they are a vaild data type of a class.
+ /// Represents an interface used to specify classes that they are a valid data type of a class.
///
public interface IDiscordInteractionData { }
}
diff --git a/src/Discord.Net.Core/Entities/Interactions/InteractionResponseType.cs b/src/Discord.Net.Core/Entities/Interactions/InteractionResponseType.cs
index 20f052f8a..ad6540698 100644
--- a/src/Discord.Net.Core/Entities/Interactions/InteractionResponseType.cs
+++ b/src/Discord.Net.Core/Entities/Interactions/InteractionResponseType.cs
@@ -1,8 +1,4 @@
using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
namespace Discord
{
@@ -13,7 +9,7 @@ namespace Discord
/// After receiving an interaction, you must respond to acknowledge it. You can choose to respond with a message immediately using
/// or you can choose to send a deferred response with . If choosing a deferred response, the user will see a loading state for the interaction,
/// and you'll have up to 15 minutes to edit the original deferred response using Edit Original Interaction Response.
- /// You can read more about Response types Here
+ /// You can read more about Response types Here.
///
public enum InteractionResponseType : byte
{
@@ -45,17 +41,17 @@ namespace Discord
DeferredChannelMessageWithSource = 5,
///
- /// For components: ACK an interaction and edit the original message later; the user does not see a loading state
+ /// For components: ACK an interaction and edit the original message later; the user does not see a loading state.
///
DeferredUpdateMessage = 6,
///
- /// For components: edit the message the component was attached to
+ /// For components: edit the message the component was attached to.
///
UpdateMessage = 7,
///
- /// Respond with a set of choices to a autocomplete interaction
+ /// Respond with a set of choices to a autocomplete interaction.
///
ApplicationCommandAutocompleteResult = 8
}
diff --git a/src/Discord.Net.Core/Entities/Interactions/InteractionType.cs b/src/Discord.Net.Core/Entities/Interactions/InteractionType.cs
index 989114505..e09c906b5 100644
--- a/src/Discord.Net.Core/Entities/Interactions/InteractionType.cs
+++ b/src/Discord.Net.Core/Entities/Interactions/InteractionType.cs
@@ -1,9 +1,3 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
namespace Discord
{
///
@@ -29,6 +23,6 @@ namespace Discord
///
/// An autocomplete request sent from discord.
///
- ApplicationCommandAutocomplete = 4,
+ ApplicationCommandAutocomplete = 4
}
}
diff --git a/src/Discord.Net.Core/Entities/Interactions/Message Components/ActionRowComponent.cs b/src/Discord.Net.Core/Entities/Interactions/Message Components/ActionRowComponent.cs
index df08e5ee3..202a5687f 100644
--- a/src/Discord.Net.Core/Entities/Interactions/Message Components/ActionRowComponent.cs
+++ b/src/Discord.Net.Core/Entities/Interactions/Message Components/ActionRowComponent.cs
@@ -1,28 +1,22 @@
-using Newtonsoft.Json;
-using System;
using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
namespace Discord
{
///
- /// Represents a Row for child components to live in.
+ /// Represents a Row for child components to live in.
///
public class ActionRowComponent : IMessageComponent
{
///
- public ComponentType Type { get; } = ComponentType.ActionRow;
+ public ComponentType Type => ComponentType.ActionRow;
///
/// Gets the child components in this row.
///
public IReadOnlyCollection Components { get; internal set; }
-
-
internal ActionRowComponent() { }
+
internal ActionRowComponent(List components)
{
Components = components;
diff --git a/src/Discord.Net.Core/Entities/Interactions/Message Components/ButtonComponent.cs b/src/Discord.Net.Core/Entities/Interactions/Message Components/ButtonComponent.cs
index 64a2ab0e9..4b9fa2753 100644
--- a/src/Discord.Net.Core/Entities/Interactions/Message Components/ButtonComponent.cs
+++ b/src/Discord.Net.Core/Entities/Interactions/Message Components/ButtonComponent.cs
@@ -1,10 +1,3 @@
-using Newtonsoft.Json;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
namespace Discord
{
///
@@ -13,7 +6,7 @@ namespace Discord
public class ButtonComponent : IMessageComponent
{
///
- public ComponentType Type { get; } = ComponentType.Button;
+ public ComponentType Type => ComponentType.Button;
///
/// Gets the of this button, example buttons with each style can be found Here.
@@ -34,7 +27,7 @@ namespace Discord
public string CustomId { get; }
///
- /// Gets the URL for a button.
+ /// Gets the URL for a button.
///
///
/// You cannot have a button with a URL and a CustomId.
diff --git a/src/Discord.Net.Core/Entities/Interactions/Message Components/ButtonStyle.cs b/src/Discord.Net.Core/Entities/Interactions/Message Components/ButtonStyle.cs
index c72767cbd..92d48ab4f 100644
--- a/src/Discord.Net.Core/Entities/Interactions/Message Components/ButtonStyle.cs
+++ b/src/Discord.Net.Core/Entities/Interactions/Message Components/ButtonStyle.cs
@@ -1,9 +1,3 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
namespace Discord
{
///
diff --git a/src/Discord.Net.Core/Entities/Interactions/Message Components/ComponentBuilder.cs b/src/Discord.Net.Core/Entities/Interactions/Message Components/ComponentBuilder.cs
index 4db96d409..48e18f29a 100644
--- a/src/Discord.Net.Core/Entities/Interactions/Message Components/ComponentBuilder.cs
+++ b/src/Discord.Net.Core/Entities/Interactions/Message Components/ComponentBuilder.cs
@@ -31,14 +31,14 @@ namespace Discord
set
{
if (value == null)
- throw new ArgumentNullException(paramName: nameof(ActionRows), message: "Cannot set an component builder's components collection to null.");
+ throw new ArgumentNullException(nameof(value), $"{nameof(ActionRows)} cannot be null.");
if (value.Count > MaxActionRowCount)
- throw new ArgumentException(message: $"Action row count must be less than or equal to {MaxActionRowCount}.", paramName: nameof(ActionRows));
+ throw new ArgumentOutOfRangeException(nameof(value), $"Action row count must be less than or equal to {MaxActionRowCount}.");
_actionRows = value;
}
}
- private List _actionRows { get; set; }
+ private List _actionRows;
///
/// Creates a new builder from a message.
@@ -56,7 +56,7 @@ namespace Discord
public static ComponentBuilder FromComponents(IReadOnlyCollection components)
{
var builder = new ComponentBuilder();
- for(int i = 0; i != components.Count; i++)
+ for (int i = 0; i != components.Count; i++)
{
var component = components.ElementAt(i);
builder.AddComponent(component, i);
@@ -118,7 +118,7 @@ namespace Discord
public ComponentBuilder WithSelectMenu(SelectMenuBuilder menu, int row = 0)
{
Preconditions.LessThan(row, MaxActionRowCount, nameof(row));
- if (menu.Options.Distinct().Count() != menu.Options.Count())
+ if (menu.Options.Distinct().Count() != menu.Options.Count)
throw new InvalidOperationException("Please make sure that there is no duplicates values.");
var builtMenu = menu.Build();
@@ -218,7 +218,7 @@ namespace Discord
else
{
ActionRowBuilder actionRow;
- if(_actionRows.Count > row)
+ if (_actionRows.Count > row)
actionRow = _actionRows.ElementAt(row);
else
{
@@ -244,10 +244,9 @@ namespace Discord
/// A that can be sent with .
public MessageComponent Build()
{
- if (_actionRows != null)
- return new MessageComponent(_actionRows.Select(x => x.Build()).ToList());
- else
- return MessageComponent.Empty;
+ return _actionRows != null
+ ? new MessageComponent(_actionRows.Select(x => x.Build()).ToList())
+ : MessageComponent.Empty;
}
}
@@ -272,19 +271,18 @@ namespace Discord
set
{
if (value == null)
- throw new ArgumentNullException(message: "Action row components cannot be null!", paramName: nameof(Components));
-
- if (value.Count <= 0)
- throw new ArgumentException(message: "There must be at least 1 component in a row", paramName: nameof(Components));
-
- if (value.Count > MaxChildCount)
- throw new ArgumentException(message: $"Action row can only contain {MaxChildCount} child components!", paramName: nameof(Components));
+ throw new ArgumentNullException(nameof(value), $"{nameof(Components)} cannot be null.");
- _components = value;
+ _components = value.Count switch
+ {
+ 0 => throw new ArgumentOutOfRangeException(nameof(value), "There must be at least 1 component in a row."),
+ > MaxChildCount => throw new ArgumentOutOfRangeException(nameof(value), $"Action row can only contain {MaxChildCount} child components!"),
+ _ => value
+ };
}
}
- private List _components { get; set; } = new List();
+ private List _components = new List();
///
/// Adds a list of components to the current row.
@@ -359,18 +357,12 @@ namespace Discord
public string Label
{
get => _label;
- set
+ set => _label = value?.Length switch
{
- if (value != null)
- {
- if (value.Length > MaxButtonLabelLength)
- throw new ArgumentException($"Button label must be {MaxButtonLabelLength} characters or less!", paramName: nameof(Label));
- if (value.Length < 1)
- throw new ArgumentException("Button label must be 1 character or more!", paramName: nameof(Label));
- }
-
- _label = value;
- }
+ > MaxButtonLabelLength => throw new ArgumentOutOfRangeException(nameof(value), $"Label length must be less or equal to {MaxButtonLabelLength}."),
+ 0 => throw new ArgumentOutOfRangeException(nameof(value), "Label length must be at least 1."),
+ _ => value
+ };
}
///
@@ -381,17 +373,12 @@ namespace Discord
public string CustomId
{
get => _customId;
- set
+ set => _customId = value?.Length switch
{
- if (value != null)
- {
- if (value.Length > ComponentBuilder.MaxCustomIdLength)
- throw new ArgumentException($"Custom Id must be {ComponentBuilder.MaxCustomIdLength} characters or less!", paramName: nameof(CustomId));
- if (value.Length < 1)
- throw new ArgumentException("Custom Id must be 1 character or more!", paramName: nameof(CustomId));
- }
- _customId = value;
- }
+ > ComponentBuilder.MaxCustomIdLength => throw new ArgumentOutOfRangeException(nameof(value), $"Custom Id length must be less or equal to {ComponentBuilder.MaxCustomIdLength}."),
+ 0 => throw new ArgumentOutOfRangeException(nameof(value), "Custom Id length must be at least 1."),
+ _ => value
+ };
}
///
@@ -414,7 +401,6 @@ namespace Discord
///
public bool IsDisabled { get; set; }
-
private string _label;
private string _customId;
@@ -594,8 +580,7 @@ namespace Discord
{
if (string.IsNullOrEmpty(Url))
throw new InvalidOperationException("Link buttons must have a link associated with them");
- else
- UrlValidation.ValidateButton(Url);
+ UrlValidation.ValidateButton(Url);
}
else if (string.IsNullOrEmpty(CustomId))
throw new InvalidOperationException("Non-link buttons must have a custom id associated with them");
@@ -632,17 +617,12 @@ namespace Discord
public string CustomId
{
get => _customId;
- set
+ set => _customId = value?.Length switch
{
- if (value != null)
- {
- if (value.Length > ComponentBuilder.MaxCustomIdLength)
- throw new ArgumentException($"Custom Id must be {ComponentBuilder.MaxCustomIdLength} characters or less!", paramName: nameof(CustomId));
- if (value.Length < 1)
- throw new ArgumentException("Custom Id must be 1 character or more!", paramName: nameof(CustomId));
- }
- _customId = value;
- }
+ > ComponentBuilder.MaxCustomIdLength => throw new ArgumentOutOfRangeException(nameof(value), $"Custom Id length must be less or equal to {ComponentBuilder.MaxCustomIdLength}."),
+ 0 => throw new ArgumentOutOfRangeException(nameof(value), "Custom Id length must be at least 1."),
+ _ => value
+ };
}
///
@@ -653,18 +633,12 @@ namespace Discord
public string Placeholder
{
get => _placeholder;
- set
+ set => _placeholder = value?.Length switch
{
- if (value != null)
- {
- if (value.Length > MaxPlaceholderLength)
- throw new ArgumentException($"The placeholder must be {MaxPlaceholderLength} characters or less!", paramName: nameof(Placeholder));
- if (value.Length < 1)
- throw new ArgumentException("The placeholder must be 1 character or more!", paramName: nameof(Placeholder));
- }
-
- _placeholder = value;
- }
+ > MaxPlaceholderLength => throw new ArgumentOutOfRangeException(nameof(value), $"Placeholder length must be less or equal to {MaxPlaceholderLength}."),
+ 0 => throw new ArgumentOutOfRangeException(nameof(value), "Placeholder length must be at least 1."),
+ _ => value
+ };
}
///
@@ -708,7 +682,7 @@ namespace Discord
if (value != null)
Preconditions.LessThan(value.Count, MaxOptionCount, nameof(Options));
else
- throw new ArgumentNullException(nameof(value));
+ throw new ArgumentNullException(nameof(value), $"{nameof(Options)} cannot be null.");
_options = value;
}
@@ -908,7 +882,7 @@ namespace Discord
/// The maximum length of a .
///
public const int MaxDescriptionLength = 100;
-
+
///
/// The maximum length of a .
///
@@ -922,42 +896,28 @@ namespace Discord
public string Label
{
get => _label;
- set
+ set => _label = value?.Length switch
{
- if (value != null)
- {
- if (value.Length > MaxSelectLabelLength)
- throw new ArgumentException($"Select option label must be {MaxSelectLabelLength} characters or less!", paramName: nameof(Label));
- if (value.Length < 1)
- throw new ArgumentException("Select option label must be 1 character or more!", paramName: nameof(Label));
- }
-
- _label = value;
- }
+ > MaxSelectLabelLength => throw new ArgumentOutOfRangeException(nameof(value), $"Label length must be less or equal to {MaxSelectLabelLength}."),
+ 0 => throw new ArgumentOutOfRangeException(nameof(value), "Label length must be at least 1."),
+ _ => value
+ };
}
///
- /// Gets or sets the custom id of the current select menu.
+ /// Gets or sets the value of the current select menu.
///
/// length exceeds .
/// length subceeds 1.
public string Value
{
get => _value;
- set
+ set => _value = value?.Length switch
{
- if (value != null)
- {
- if (value.Length > MaxSelectValueLength)
- throw new ArgumentException($"Select option value must be {MaxSelectValueLength} characters or less!", paramName: nameof(Label));
- if (value.Length < 1)
- throw new ArgumentException("Select option value must be 1 character or more!", paramName: nameof(Label));
- }
- else
- throw new ArgumentException("Select option value must not be null or empty!", paramName: nameof(Label));
-
- _value = value;
- }
+ > MaxSelectValueLength => throw new ArgumentOutOfRangeException(nameof(value), $"Value length must be less or equal to {MaxSelectValueLength}."),
+ 0 => throw new ArgumentOutOfRangeException(nameof(value), "Value length must be at least 1."),
+ _ => value
+ };
}
///
@@ -968,18 +928,12 @@ namespace Discord
public string Description
{
get => _description;
- set
+ set => _description = value?.Length switch
{
- if (value != null)
- {
- if (value.Length > MaxDescriptionLength)
- throw new ArgumentException($"The description must be {MaxDescriptionLength} characters or less!", paramName: nameof(Label));
- if (value.Length < 1)
- throw new ArgumentException("The description must be 1 character or more!", paramName: nameof(Label));
- }
-
- _description = value;
- }
+ > MaxDescriptionLength => throw new ArgumentOutOfRangeException(nameof(value), $"Description length must be less or equal to {MaxDescriptionLength}."),
+ 0 => throw new ArgumentOutOfRangeException(nameof(value), "Description length must be at least 1."),
+ _ => value
+ };
}
///
diff --git a/src/Discord.Net.Core/Entities/Interactions/Message Components/ComponentType.cs b/src/Discord.Net.Core/Entities/Interactions/Message Components/ComponentType.cs
index 5fb4fc092..70bc1f301 100644
--- a/src/Discord.Net.Core/Entities/Interactions/Message Components/ComponentType.cs
+++ b/src/Discord.Net.Core/Entities/Interactions/Message Components/ComponentType.cs
@@ -1,29 +1,23 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
namespace Discord
{
///
- /// Represents a type of a component
+ /// Represents a type of a component.
///
public enum ComponentType
{
///
- /// A container for other components
+ /// A container for other components.
///
ActionRow = 1,
///
- /// A clickable button
+ /// A clickable button.
///
Button = 2,
///
- /// A select menu for picking from choices
+ /// A select menu for picking from choices.
///
- SelectMenu = 3,
+ SelectMenu = 3
}
}
diff --git a/src/Discord.Net.Core/Entities/Interactions/Message Components/IMessageComponent.cs b/src/Discord.Net.Core/Entities/Interactions/Message Components/IMessageComponent.cs
index 7614fbfd5..9366a44d6 100644
--- a/src/Discord.Net.Core/Entities/Interactions/Message Components/IMessageComponent.cs
+++ b/src/Discord.Net.Core/Entities/Interactions/Message Components/IMessageComponent.cs
@@ -1,9 +1,3 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
namespace Discord
{
///
diff --git a/src/Discord.Net.Core/Entities/Interactions/Message Components/MessageComponent.cs b/src/Discord.Net.Core/Entities/Interactions/Message Components/MessageComponent.cs
index eb37a57b8..720588681 100644
--- a/src/Discord.Net.Core/Entities/Interactions/Message Components/MessageComponent.cs
+++ b/src/Discord.Net.Core/Entities/Interactions/Message Components/MessageComponent.cs
@@ -1,8 +1,4 @@
-using System;
using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
namespace Discord
{
diff --git a/src/Discord.Net.Core/Entities/Interactions/Message Components/SelectMenuComponent.cs b/src/Discord.Net.Core/Entities/Interactions/Message Components/SelectMenuComponent.cs
index a0b980c53..dfea84710 100644
--- a/src/Discord.Net.Core/Entities/Interactions/Message Components/SelectMenuComponent.cs
+++ b/src/Discord.Net.Core/Entities/Interactions/Message Components/SelectMenuComponent.cs
@@ -1,8 +1,5 @@
-using System;
using System.Collections.Generic;
using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
namespace Discord
{
diff --git a/src/Discord.Net.Core/Entities/Interactions/Message Components/SelectMenuOption.cs b/src/Discord.Net.Core/Entities/Interactions/Message Components/SelectMenuOption.cs
index 624b652be..755068b2d 100644
--- a/src/Discord.Net.Core/Entities/Interactions/Message Components/SelectMenuOption.cs
+++ b/src/Discord.Net.Core/Entities/Interactions/Message Components/SelectMenuOption.cs
@@ -1,9 +1,3 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
namespace Discord
{
///
diff --git a/src/Discord.Net.Core/Entities/Interactions/Slash Commands/SlashCommandBuilder.cs b/src/Discord.Net.Core/Entities/Interactions/Slash Commands/SlashCommandBuilder.cs
index 7402a6e66..c42934bcf 100644
--- a/src/Discord.Net.Core/Entities/Interactions/Slash Commands/SlashCommandBuilder.cs
+++ b/src/Discord.Net.Core/Entities/Interactions/Slash Commands/SlashCommandBuilder.cs
@@ -1,9 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
-using System.Text;
using System.Text.RegularExpressions;
-using System.Threading.Tasks;
namespace Discord
{
@@ -30,20 +28,17 @@ namespace Discord
///
public string Name
{
- get
- {
- return _name;
- }
+ get => _name;
set
{
- Preconditions.NotNullOrEmpty(value, nameof(Name));
- Preconditions.AtLeast(value.Length, 1, nameof(Name));
- Preconditions.AtMost(value.Length, MaxNameLength, nameof(Name));
+ Preconditions.NotNullOrEmpty(value, nameof(value));
+ Preconditions.AtLeast(value.Length, 1, nameof(value));
+ Preconditions.AtMost(value.Length, MaxNameLength, nameof(value));
// Discord updated the docs, this regex prevents special characters like @!$%(... etc,
// https://discord.com/developers/docs/interactions/slash-commands#applicationcommand
if (!Regex.IsMatch(value, @"^[\w-]{1,32}$"))
- throw new ArgumentException("Command name cannot contain any special characters or whitespaces!");
+ throw new ArgumentException("Command name cannot contain any special characters or whitespaces!", nameof(value));
_name = value;
}
@@ -55,10 +50,7 @@ namespace Discord
///
public string Description
{
- get
- {
- return _description;
- }
+ get => _description;
set
{
Preconditions.NotNullOrEmpty(value, nameof(Description));
@@ -77,10 +69,7 @@ namespace Discord
get => _options;
set
{
- if (value != null)
- if (value.Count > MaxOptionsCount)
- throw new ArgumentException(message: $"Option count must be less than or equal to {MaxOptionsCount}.", paramName: nameof(Options));
-
+ Preconditions.AtMost(value?.Count ?? 0, MaxOptionsCount, nameof(value));
_options = value;
}
}
@@ -90,9 +79,9 @@ namespace Discord
///
public bool DefaultPermission { get; set; } = true;
- private string _name { get; set; }
- private string _description { get; set; }
- private List _options { get; set; }
+ private string _name;
+ private string _description;
+ private List _options;
///
/// Build the current builder into a class.
@@ -100,11 +89,11 @@ namespace Discord
/// A that can be used to create slash commands over rest.
public SlashCommandProperties Build()
{
- SlashCommandProperties props = new SlashCommandProperties()
+ var props = new SlashCommandProperties
{
Name = Name,
Description = Description,
- DefaultPermission = DefaultPermission,
+ DefaultPermission = DefaultPermission
};
if (Options != null && Options.Any())
@@ -117,7 +106,6 @@ namespace Discord
}
return props;
-
}
///
@@ -163,7 +151,7 @@ namespace Discord
/// The description of this option.
/// If this option is required for this command.
/// If this option is the default option.
- /// If this option is set to autocompleate.
+ /// If this option is set to autocomplete.
/// The options of the option to add.
/// The allowed channel types for this option.
/// The choices of this option.
@@ -188,14 +176,10 @@ namespace Discord
Preconditions.AtMost(description.Length, MaxDescriptionLength, nameof(description));
// make sure theres only one option with default set to true
- if (isDefault.HasValue && isDefault.Value)
- {
- if (Options != null)
- if (Options.Any(x => x.Default.HasValue && x.Default.Value))
- throw new ArgumentException("There can only be one command option with default set to true!", nameof(isDefault));
- }
+ if (isDefault == true && Options?.Any(x => x.Default == true) == true)
+ throw new ArgumentException("There can only be one command option with default set to true!", nameof(isDefault));
- SlashCommandOptionBuilder option = new SlashCommandOptionBuilder
+ var option = new SlashCommandOptionBuilder
{
Name = name,
Description = description,
@@ -204,8 +188,8 @@ namespace Discord
Options = options,
Type = type,
Autocomplete = isAutocomplete,
- Choices = choices != null ? new List(choices) : null,
- ChannelTypes = channelTypes,
+ Choices = (choices ?? Array.Empty()).ToList(),
+ ChannelTypes = channelTypes
};
return AddOption(option);
@@ -228,14 +212,12 @@ namespace Discord
/// The current builder.
public SlashCommandBuilder AddOption(SlashCommandOptionBuilder option)
{
- if (Options == null)
- Options = new List();
+ Options ??= new List();
if (Options.Count >= MaxOptionsCount)
- throw new ArgumentOutOfRangeException(nameof(Options), $"Cannot have more than {MaxOptionsCount} options!");
+ throw new InvalidOperationException($"Cannot have more than {MaxOptionsCount} options!");
- if (option == null)
- throw new ArgumentNullException(nameof(option), "Option cannot be null");
+ Preconditions.NotNull(option, nameof(option));
Options.Add(option);
return this;
@@ -251,10 +233,9 @@ namespace Discord
throw new ArgumentNullException(nameof(options), "Options cannot be null!");
if (options.Length == 0)
- throw new ArgumentException(nameof(options), "Options cannot be empty!");
+ throw new ArgumentException("Options cannot be empty!", nameof(options));
- if (Options == null)
- Options = new List();
+ Options ??= new List();
if (Options.Count + options.Length > MaxOptionsCount)
throw new ArgumentOutOfRangeException(nameof(options), $"Cannot have more than {MaxOptionsCount} options!");
@@ -290,14 +271,13 @@ namespace Discord
get => _name;
set
{
- if (value?.Length > SlashCommandBuilder.MaxNameLength)
- throw new ArgumentException($"Name length must be less than or equal to {SlashCommandBuilder.MaxNameLength}");
- if (value?.Length < 1)
- throw new ArgumentException("Name length must at least 1 characters in length");
-
if (value != null)
+ {
+ Preconditions.AtLeast(value.Length, 1, nameof(value));
+ Preconditions.AtMost(value.Length, SlashCommandBuilder.MaxNameLength, nameof(value));
if (!Regex.IsMatch(value, @"^[\w-]{1,32}$"))
- throw new ArgumentException("Option name cannot contain any special characters or whitespaces!");
+ throw new ArgumentException("Option name cannot contain any special characters or whitespaces!", nameof(value));
+ }
_name = value;
}
@@ -311,10 +291,11 @@ namespace Discord
get => _description;
set
{
- if (value?.Length > SlashCommandBuilder.MaxDescriptionLength)
- throw new ArgumentException($"Description length must be less than or equal to {SlashCommandBuilder.MaxDescriptionLength}");
- if (value?.Length < 1)
- throw new ArgumentException("Description length must at least 1 character in length");
+ if (value != null)
+ {
+ Preconditions.AtLeast(value.Length, 1, nameof(value));
+ Preconditions.AtMost(value.Length, SlashCommandBuilder.MaxDescriptionLength, nameof(value));
+ }
_description = value;
}
@@ -333,7 +314,7 @@ namespace Discord
///
/// Gets or sets if the option is required.
///
- public bool? Required { get; set; } = null;
+ public bool? Required { get; set; }
///
/// Gets or sets whether or not this option supports autocomplete.
@@ -364,19 +345,19 @@ namespace Discord
bool isSubType = Type == ApplicationCommandOptionType.SubCommandGroup;
if (isSubType && (Options == null || !Options.Any()))
- throw new ArgumentException(nameof(Options), "SubCommands/SubCommandGroups must have at least one option");
+ throw new InvalidOperationException("SubCommands/SubCommandGroups must have at least one option");
- if (!isSubType && (Options != null && Options.Any()) && Type != ApplicationCommandOptionType.SubCommand)
- throw new ArgumentException(nameof(Options), $"Cannot have options on {Type} type");
+ if (!isSubType && Options != null && Options.Any() && Type != ApplicationCommandOptionType.SubCommand)
+ throw new InvalidOperationException($"Cannot have options on {Type} type");
- return new ApplicationCommandOptionProperties()
+ return new ApplicationCommandOptionProperties
{
Name = Name,
Description = Description,
Default = Default,
Required = Required,
Type = Type,
- Options = Options?.Count > 0 ? new List(Options.Select(x => x.Build())) : null,
+ Options = Options?.Count > 0 ? Options.Select(x => x.Build()).ToList() : new List(),
Choices = Choices,
Autocomplete = Autocomplete,
ChannelTypes = ChannelTypes
@@ -416,14 +397,10 @@ namespace Discord
Preconditions.AtMost(description.Length, SlashCommandBuilder.MaxDescriptionLength, nameof(description));
// make sure theres only one option with default set to true
- if (isDefault)
- {
- if (Options != null)
- if (Options.Any(x => x.Default.HasValue && x.Default.Value))
- throw new ArgumentException("There can only be one command option with default set to true!", nameof(isDefault));
- }
+ if (isDefault && Options?.Any(x => x.Default == true) == true)
+ throw new ArgumentException("There can only be one command option with default set to true!", nameof(isDefault));
- SlashCommandOptionBuilder option = new SlashCommandOptionBuilder
+ var option = new SlashCommandOptionBuilder
{
Name = name,
Description = description,
@@ -432,8 +409,8 @@ namespace Discord
Autocomplete = isAutocomplete,
Options = options,
Type = type,
- Choices = choices != null ? new List(choices) : null,
- ChannelTypes = channelTypes,
+ Choices = (choices ?? Array.Empty()).ToList(),
+ ChannelTypes = channelTypes
};
return AddOption(option);
@@ -445,14 +422,12 @@ namespace Discord
/// The current builder.
public SlashCommandOptionBuilder AddOption(SlashCommandOptionBuilder option)
{
- if (Options == null)
- Options = new List();
+ Options ??= new List();
if (Options.Count >= SlashCommandBuilder.MaxOptionsCount)
- throw new ArgumentOutOfRangeException(nameof(Choices), $"There can only be {SlashCommandBuilder.MaxOptionsCount} options per sub command group!");
+ throw new InvalidOperationException($"There can only be {SlashCommandBuilder.MaxOptionsCount} options per sub command group!");
- if (option == null)
- throw new ArgumentNullException(nameof(option), "Option cannot be null");
+ Preconditions.NotNull(option, nameof(option));
Options.Add(option);
return this;
@@ -466,19 +441,17 @@ namespace Discord
/// The current builder.
public SlashCommandOptionBuilder AddChoice(string name, int value)
{
- if (Choices == null)
- Choices = new List();
+ Choices ??= new List();
if (Choices.Count >= MaxChoiceCount)
- throw new ArgumentOutOfRangeException(nameof(Choices), $"Cannot add more than {MaxChoiceCount} choices!");
+ throw new InvalidOperationException($"Cannot add more than {MaxChoiceCount} choices!");
- if (name == null)
- throw new ArgumentNullException($"{nameof(name)} cannot be null!");
+ Preconditions.NotNull(name, nameof(name));
Preconditions.AtLeast(name.Length, 1, nameof(name));
Preconditions.AtMost(name.Length, 100, nameof(name));
- Choices.Add(new ApplicationCommandOptionChoiceProperties()
+ Choices.Add(new ApplicationCommandOptionChoiceProperties
{
Name = name,
Value = value
@@ -495,17 +468,13 @@ namespace Discord
/// The current builder.
public SlashCommandOptionBuilder AddChoice(string name, string value)
{
- if (Choices == null)
- Choices = new List();
+ Choices ??= new List();
if (Choices.Count >= MaxChoiceCount)
- throw new ArgumentOutOfRangeException(nameof(Choices), $"Cannot add more than {MaxChoiceCount} choices!");
-
- if (name == null)
- throw new ArgumentNullException($"{nameof(name)} cannot be null!");
+ throw new InvalidOperationException($"Cannot add more than {MaxChoiceCount} choices!");
- if (value == null)
- throw new ArgumentNullException($"{nameof(value)} cannot be null!");
+ Preconditions.NotNull(name, nameof(name));
+ Preconditions.NotNull(value, nameof(value));
Preconditions.AtLeast(name.Length, 1, nameof(name));
Preconditions.AtMost(name.Length, 100, nameof(name));
@@ -513,7 +482,7 @@ namespace Discord
Preconditions.AtLeast(value.Length, 1, nameof(value));
Preconditions.AtMost(value.Length, 100, nameof(value));
- Choices.Add(new ApplicationCommandOptionChoiceProperties()
+ Choices.Add(new ApplicationCommandOptionChoiceProperties
{
Name = name,
Value = value
@@ -523,14 +492,13 @@ namespace Discord
}
///
- /// Adds a channnel type to the current option.
+ /// Adds a channel type to the current option.
///
/// The to add.
/// The current builder.
public SlashCommandOptionBuilder AddChannelType(ChannelType channelType)
{
- if (ChannelTypes == null)
- ChannelTypes = new List();
+ ChannelTypes ??= new List();
ChannelTypes.Add(channelType);
diff --git a/src/Discord.Net.Core/Entities/Interactions/Slash Commands/SlashCommandProperties.cs b/src/Discord.Net.Core/Entities/Interactions/Slash Commands/SlashCommandProperties.cs
index 542170b94..6f320ffeb 100644
--- a/src/Discord.Net.Core/Entities/Interactions/Slash Commands/SlashCommandProperties.cs
+++ b/src/Discord.Net.Core/Entities/Interactions/Slash Commands/SlashCommandProperties.cs
@@ -1,8 +1,4 @@
-using System;
using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
namespace Discord
{
diff --git a/src/Discord.Net.Core/Entities/Messages/StickerFormatType.cs b/src/Discord.Net.Core/Entities/Messages/StickerFormatType.cs
index d24a38534..82e6b15a4 100644
--- a/src/Discord.Net.Core/Entities/Messages/StickerFormatType.cs
+++ b/src/Discord.Net.Core/Entities/Messages/StickerFormatType.cs
@@ -1,15 +1,25 @@
namespace Discord
{
- /// Defines the types of formats for stickers.
+ ///
+ /// Defines the types of formats for stickers.
+ ///
public enum StickerFormatType
{
- /// Default value for a sticker format type.
+ ///
+ /// Default value for a sticker format type.
+ ///
None = 0,
- /// The sticker format type is png.
+ ///
+ /// The sticker format type is png.
+ ///
Png = 1,
- /// The sticker format type is apng.
+ ///
+ /// The sticker format type is apng.
+ ///
Apng = 2,
- /// The sticker format type is lottie.
- Lottie = 3,
+ ///
+ /// The sticker format type is lottie.
+ ///
+ Lottie = 3
}
}
diff --git a/src/Discord.Net.Core/Entities/Messages/TimestampTag.cs b/src/Discord.Net.Core/Entities/Messages/TimestampTag.cs
index 21d30456f..347b0daaa 100644
--- a/src/Discord.Net.Core/Entities/Messages/TimestampTag.cs
+++ b/src/Discord.Net.Core/Entities/Messages/TimestampTag.cs
@@ -1,8 +1,4 @@
using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
namespace Discord
{
@@ -24,18 +20,13 @@ namespace Discord
///
/// Converts the current timestamp tag to the string representation supported by discord.
///
- /// If the is null then the default 0 will be used.
+ /// If the is null then the default 0 will be used.
///
///
- /// A string thats compatible in a discord message, ex: <t:1625944201:f>
+ /// A string that is compatible in a discord message, ex: <t:1625944201:f>
public override string ToString()
{
- if (Time == null)
- return $"";
-
- var offset = (DateTimeOffset)this.Time;
-
- return $"";
+ return $"";
}
///
@@ -46,7 +37,7 @@ namespace Discord
/// The newly create timestamp tag.
public static TimestampTag FromDateTime(DateTime time, TimestampTagStyles style = TimestampTagStyles.ShortDateTime)
{
- return new TimestampTag()
+ return new TimestampTag
{
Style = style,
Time = time
diff --git a/src/Discord.Net.Core/Entities/Messages/TimestampTagStyle.cs b/src/Discord.Net.Core/Entities/Messages/TimestampTagStyle.cs
index 9c83a070e..89f3c79b5 100644
--- a/src/Discord.Net.Core/Entities/Messages/TimestampTagStyle.cs
+++ b/src/Discord.Net.Core/Entities/Messages/TimestampTagStyle.cs
@@ -1,9 +1,3 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
namespace Discord
{
///
diff --git a/src/Discord.Net.Core/Entities/Permissions/ApplicationCommandPermissionTarget.cs b/src/Discord.Net.Core/Entities/Permissions/ApplicationCommandPermissionTarget.cs
index 5410075ba..9a99b34f1 100644
--- a/src/Discord.Net.Core/Entities/Permissions/ApplicationCommandPermissionTarget.cs
+++ b/src/Discord.Net.Core/Entities/Permissions/ApplicationCommandPermissionTarget.cs
@@ -1,9 +1,3 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
namespace Discord
{
///
@@ -18,6 +12,6 @@ namespace Discord
///
/// The target of the permission is a user.
///
- User = 2,
+ User = 2
}
}
diff --git a/src/Discord.Net.Core/Entities/Permissions/GuildApplicationCommandPermissions.cs b/src/Discord.Net.Core/Entities/Permissions/GuildApplicationCommandPermissions.cs
index 4be724453..e738fec4c 100644
--- a/src/Discord.Net.Core/Entities/Permissions/GuildApplicationCommandPermissions.cs
+++ b/src/Discord.Net.Core/Entities/Permissions/GuildApplicationCommandPermissions.cs
@@ -1,8 +1,4 @@
-using System;
using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
namespace Discord
{
diff --git a/src/Discord.Net.Core/Entities/Stickers/ICustomSticker.cs b/src/Discord.Net.Core/Entities/Stickers/ICustomSticker.cs
index ff06a4342..9cba38c80 100644
--- a/src/Discord.Net.Core/Entities/Stickers/ICustomSticker.cs
+++ b/src/Discord.Net.Core/Entities/Stickers/ICustomSticker.cs
@@ -1,7 +1,4 @@
using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
using System.Threading.Tasks;
namespace Discord
diff --git a/src/Discord.Net.Core/Entities/Stickers/ISticker.cs b/src/Discord.Net.Core/Entities/Stickers/ISticker.cs
index a3c520b4a..9deea753f 100644
--- a/src/Discord.Net.Core/Entities/Stickers/ISticker.cs
+++ b/src/Discord.Net.Core/Entities/Stickers/ISticker.cs
@@ -1,6 +1,4 @@
-using System;
using System.Collections.Generic;
-using System.Threading.Tasks;
namespace Discord
{
@@ -57,12 +55,12 @@ namespace Discord
new StickerFormatType Format { get; }
///
- /// Gets whether this guild sticker can be used, may be false due to loss of Server Boosts
+ /// Gets whether this guild sticker can be used, may be false due to loss of Server Boosts.
///
bool? IsAvailable { get; }
///
- /// Gets the standard sticker's sort order within its pack
+ /// Gets the standard sticker's sort order within its pack.
///
int? SortOrder { get; }
///
diff --git a/src/Discord.Net.Core/Entities/Stickers/IStickerItem.cs b/src/Discord.Net.Core/Entities/Stickers/IStickerItem.cs
index 3825a2702..07ea63db9 100644
--- a/src/Discord.Net.Core/Entities/Stickers/IStickerItem.cs
+++ b/src/Discord.Net.Core/Entities/Stickers/IStickerItem.cs
@@ -1,9 +1,3 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
namespace Discord
{
///
diff --git a/src/Discord.Net.Core/Entities/Stickers/StickerPack.cs b/src/Discord.Net.Core/Entities/Stickers/StickerPack.cs
index 76d424a47..c0c90aa69 100644
--- a/src/Discord.Net.Core/Entities/Stickers/StickerPack.cs
+++ b/src/Discord.Net.Core/Entities/Stickers/StickerPack.cs
@@ -1,16 +1,12 @@
-using System;
using System.Collections.Generic;
using System.Collections.Immutable;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
namespace Discord
{
///
/// Represents a discord sticker pack.
///
- /// The type of the stickers within the collection
+ /// The type of the stickers within the collection.
public class StickerPack where TSticker : ISticker
{
///
diff --git a/src/Discord.Net.Core/Entities/Stickers/StickerProperties.cs b/src/Discord.Net.Core/Entities/Stickers/StickerProperties.cs
index 21267cdda..5f51e5f3d 100644
--- a/src/Discord.Net.Core/Entities/Stickers/StickerProperties.cs
+++ b/src/Discord.Net.Core/Entities/Stickers/StickerProperties.cs
@@ -1,8 +1,4 @@
-using System;
using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
namespace Discord
{
diff --git a/src/Discord.Net.Core/Entities/Stickers/StickerType.cs b/src/Discord.Net.Core/Entities/Stickers/StickerType.cs
index 35946df7a..0db550772 100644
--- a/src/Discord.Net.Core/Entities/Stickers/StickerType.cs
+++ b/src/Discord.Net.Core/Entities/Stickers/StickerType.cs
@@ -1,13 +1,7 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
namespace Discord
{
///
- /// Represents a type of sticker
+ /// Represents a type of sticker..
///
public enum StickerType
{
@@ -19,6 +13,6 @@ namespace Discord
///
/// Represents a sticker that was created within a guild.
///
- Guild = 2,
+ Guild = 2
}
}
diff --git a/src/Discord.Net.Core/Net/ApplicationCommandException.cs b/src/Discord.Net.Core/Net/ApplicationCommandException.cs
index acf19afe4..62c80b388 100644
--- a/src/Discord.Net.Core/Net/ApplicationCommandException.cs
+++ b/src/Discord.Net.Core/Net/ApplicationCommandException.cs
@@ -1,8 +1,4 @@
using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
namespace Discord.Net
{
diff --git a/src/Discord.Net.Core/Utils/UrlValidation.cs b/src/Discord.Net.Core/Utils/UrlValidation.cs
index fd1642f5c..ab651da0d 100644
--- a/src/Discord.Net.Core/Utils/UrlValidation.cs
+++ b/src/Discord.Net.Core/Utils/UrlValidation.cs
@@ -2,38 +2,38 @@ using System;
namespace Discord.Utils
{
- static class UrlValidation
+ internal static class UrlValidation
{
///
/// Not full URL validation right now. Just ensures protocol is present and that it's either http or https
- /// should be used for url buttons
+ /// should be used for url buttons.
///
- /// url to validate before sending to Discord.
+ /// The URL to validate before sending to Discord.
/// A URL must include a protocol (http or https).
- /// true if url is valid by our standard, false if null, throws an error upon invalid
+ /// true if URL is valid by our standard, false if null, throws an error upon invalid.
public static bool Validate(string url)
{
if (string.IsNullOrEmpty(url))
return false;
- if(!(url.StartsWith("http://", StringComparison.OrdinalIgnoreCase) || (url.StartsWith("https://", StringComparison.OrdinalIgnoreCase))))
+ if (!(url.StartsWith("http://", StringComparison.OrdinalIgnoreCase) || url.StartsWith("https://", StringComparison.OrdinalIgnoreCase)))
throw new InvalidOperationException($"The url {url} must include a protocol (either HTTP or HTTPS)");
return true;
}
///
/// Not full URL validation right now. Just Ensures the protocol is either http, https, or discord
- /// should be used everything other than url buttons
+ /// should be used everything other than url buttons.
///
- /// the url to validate before sending to discord
+ /// The URL to validate before sending to discord.
/// A URL must include a protocol (either http, https, or discord).
- /// true if the url is valid by our standard, false if null, throws an error upon invalid
+ /// true if the URL is valid by our standard, false if null, throws an error upon invalid.
public static bool ValidateButton(string url)
{
if (string.IsNullOrEmpty(url))
return false;
- if(!((url.StartsWith("http://", StringComparison.OrdinalIgnoreCase)) ||
- (url.StartsWith("https://", StringComparison.OrdinalIgnoreCase)) ||
- (url.StartsWith("discord://", StringComparison.OrdinalIgnoreCase))))
+ if (!(url.StartsWith("http://", StringComparison.OrdinalIgnoreCase) ||
+ url.StartsWith("https://", StringComparison.OrdinalIgnoreCase) ||
+ url.StartsWith("discord://", StringComparison.OrdinalIgnoreCase)))
throw new InvalidOperationException($"The url {url} must include a protocol (either HTTP, HTTPS, or DISCORD)");
return true;
}
diff --git a/src/Discord.Net.Rest/API/Common/ActionRowComponent.cs b/src/Discord.Net.Rest/API/Common/ActionRowComponent.cs
index 92778849c..9dede7e03 100644
--- a/src/Discord.Net.Rest/API/Common/ActionRowComponent.cs
+++ b/src/Discord.Net.Rest/API/Common/ActionRowComponent.cs
@@ -1,10 +1,5 @@
using Newtonsoft.Json;
-using Newtonsoft.Json.Linq;
-using System;
-using System.Collections.Generic;
using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
namespace Discord.API
{
@@ -26,7 +21,7 @@ namespace Discord.API
{
ComponentType.Button => new ButtonComponent(x as Discord.ButtonComponent),
ComponentType.SelectMenu => new SelectMenuComponent(x as Discord.SelectMenuComponent),
- _ => null,
+ _ => null
};
}).ToArray();
}
diff --git a/src/Discord.Net.Rest/API/Common/ApplicationCommand.cs b/src/Discord.Net.Rest/API/Common/ApplicationCommand.cs
index 9de272706..81598b96e 100644
--- a/src/Discord.Net.Rest/API/Common/ApplicationCommand.cs
+++ b/src/Discord.Net.Rest/API/Common/ApplicationCommand.cs
@@ -1,9 +1,4 @@
using Newtonsoft.Json;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
namespace Discord.API
{
diff --git a/src/Discord.Net.Rest/API/Common/ApplicationCommandInteractionData.cs b/src/Discord.Net.Rest/API/Common/ApplicationCommandInteractionData.cs
index bb395df13..a98ed77d6 100644
--- a/src/Discord.Net.Rest/API/Common/ApplicationCommandInteractionData.cs
+++ b/src/Discord.Net.Rest/API/Common/ApplicationCommandInteractionData.cs
@@ -1,5 +1,4 @@
using Newtonsoft.Json;
-using System.Collections.Generic;
namespace Discord.API
{
@@ -19,6 +18,5 @@ namespace Discord.API
[JsonProperty("type")]
public ApplicationCommandType Type { get; set; }
-
}
}
diff --git a/src/Discord.Net.Rest/API/Common/ApplicationCommandInteractionDataOption.cs b/src/Discord.Net.Rest/API/Common/ApplicationCommandInteractionDataOption.cs
index 5f75c901f..1e488c4e6 100644
--- a/src/Discord.Net.Rest/API/Common/ApplicationCommandInteractionDataOption.cs
+++ b/src/Discord.Net.Rest/API/Common/ApplicationCommandInteractionDataOption.cs
@@ -1,5 +1,4 @@
using Newtonsoft.Json;
-using System.Collections.Generic;
namespace Discord.API
{
diff --git a/src/Discord.Net.Rest/API/Common/ApplicationCommandOption.cs b/src/Discord.Net.Rest/API/Common/ApplicationCommandOption.cs
index f1c4cce42..67fce2bb5 100644
--- a/src/Discord.Net.Rest/API/Common/ApplicationCommandOption.cs
+++ b/src/Discord.Net.Rest/API/Common/ApplicationCommandOption.cs
@@ -1,9 +1,5 @@
using Newtonsoft.Json;
-using System;
-using System.Collections.Generic;
using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
namespace Discord.API
{
@@ -40,7 +36,7 @@ namespace Discord.API
public ApplicationCommandOption(IApplicationCommandOption cmd)
{
- Choices = cmd.Choices.Select(x => new ApplicationCommandOptionChoice()
+ Choices = cmd.Choices.Select(x => new ApplicationCommandOptionChoice
{
Name = x.Name,
Value = x.Value
@@ -50,42 +46,28 @@ namespace Discord.API
ChannelTypes = cmd.ChannelTypes.ToArray();
- Required = cmd.IsRequired.HasValue
- ? cmd.IsRequired.Value
- : Optional.Unspecified;
- Default = cmd.IsDefault.HasValue
- ? cmd.IsDefault.Value
- : Optional.Unspecified;
+ Required = cmd.IsRequired ?? Optional.Unspecified;
+ Default = cmd.IsDefault ?? Optional.Unspecified;
Name = cmd.Name;
Type = cmd.Type;
Description = cmd.Description;
}
- public ApplicationCommandOption(Discord.ApplicationCommandOptionProperties option)
+ public ApplicationCommandOption(ApplicationCommandOptionProperties option)
{
- Choices = option.Choices != null
- ? option.Choices.Select(x => new ApplicationCommandOptionChoice()
- {
- Name = x.Name,
- Value = x.Value
- }).ToArray()
- : Optional.Unspecified;
-
- Options = option.Options != null
- ? option.Options.Select(x => new ApplicationCommandOption(x)).ToArray()
- : Optional.Unspecified;
-
- Required = option.Required.HasValue
- ? option.Required.Value
- : Optional.Unspecified;
-
- Default = option.Default.HasValue
- ? option.Default.Value
- : Optional.Unspecified;
-
- ChannelTypes = option.ChannelTypes != null
- ? option.ChannelTypes.ToArray()
- : Optional.Unspecified;
+ Choices = option.Choices?.Select(x => new ApplicationCommandOptionChoice
+ {
+ Name = x.Name,
+ Value = x.Value
+ }).ToArray() ?? Optional.Unspecified;
+
+ Options = option.Options?.Select(x => new ApplicationCommandOption(x)).ToArray() ?? Optional.Unspecified;
+
+ Required = option.Required ?? Optional.Unspecified;
+
+ Default = option.Default ?? Optional.Unspecified;
+
+ ChannelTypes = option.ChannelTypes?.ToArray() ?? Optional.Unspecified;
Name = option.Name;
Type = option.Type;
diff --git a/src/Discord.Net.Rest/API/Common/ApplicationCommandOptionChoice.cs b/src/Discord.Net.Rest/API/Common/ApplicationCommandOptionChoice.cs
index b847fceba..6f84437f6 100644
--- a/src/Discord.Net.Rest/API/Common/ApplicationCommandOptionChoice.cs
+++ b/src/Discord.Net.Rest/API/Common/ApplicationCommandOptionChoice.cs
@@ -1,9 +1,4 @@
using Newtonsoft.Json;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
namespace Discord.API
{
diff --git a/src/Discord.Net.Rest/API/Common/ApplicationCommandPermissions.cs b/src/Discord.Net.Rest/API/Common/ApplicationCommandPermissions.cs
index 281ded90f..8bde80f50 100644
--- a/src/Discord.Net.Rest/API/Common/ApplicationCommandPermissions.cs
+++ b/src/Discord.Net.Rest/API/Common/ApplicationCommandPermissions.cs
@@ -1,9 +1,4 @@
using Newtonsoft.Json;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
namespace Discord.API
{
diff --git a/src/Discord.Net.Rest/API/Common/AutocompleteInteractionData.cs b/src/Discord.Net.Rest/API/Common/AutocompleteInteractionData.cs
index ea2cd4fd9..2184a0e98 100644
--- a/src/Discord.Net.Rest/API/Common/AutocompleteInteractionData.cs
+++ b/src/Discord.Net.Rest/API/Common/AutocompleteInteractionData.cs
@@ -1,9 +1,4 @@
using Newtonsoft.Json;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
namespace Discord.API
{
diff --git a/src/Discord.Net.Rest/API/Common/AutocompleteInteractionDataOption.cs b/src/Discord.Net.Rest/API/Common/AutocompleteInteractionDataOption.cs
index 1ea3ad54a..1419f93b6 100644
--- a/src/Discord.Net.Rest/API/Common/AutocompleteInteractionDataOption.cs
+++ b/src/Discord.Net.Rest/API/Common/AutocompleteInteractionDataOption.cs
@@ -1,9 +1,4 @@
using Newtonsoft.Json;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
namespace Discord.API
{
diff --git a/src/Discord.Net.Rest/API/Common/ButtonComponent.cs b/src/Discord.Net.Rest/API/Common/ButtonComponent.cs
index 887040006..7f737d7ad 100644
--- a/src/Discord.Net.Rest/API/Common/ButtonComponent.cs
+++ b/src/Discord.Net.Rest/API/Common/ButtonComponent.cs
@@ -1,9 +1,4 @@
using Newtonsoft.Json;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
namespace Discord.API
{
@@ -45,16 +40,16 @@ namespace Discord.API
{
if (c.Emote is Emote e)
{
- Emote = new Emoji()
+ Emote = new Emoji
{
Name = e.Name,
Animated = e.Animated,
- Id = e.Id,
+ Id = e.Id
};
}
else
{
- Emote = new Emoji()
+ Emote = new Emoji
{
Name = c.Emote.Name
};
diff --git a/src/Discord.Net.Rest/API/Common/ChannelThreads.cs b/src/Discord.Net.Rest/API/Common/ChannelThreads.cs
index eccac8e54..94b2396bf 100644
--- a/src/Discord.Net.Rest/API/Common/ChannelThreads.cs
+++ b/src/Discord.Net.Rest/API/Common/ChannelThreads.cs
@@ -1,9 +1,4 @@
using Newtonsoft.Json;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
namespace Discord.API.Rest
{
diff --git a/src/Discord.Net.Rest/API/Common/GuildApplicationCommandPermissions.cs b/src/Discord.Net.Rest/API/Common/GuildApplicationCommandPermissions.cs
index 3ab5ef650..cc74299f7 100644
--- a/src/Discord.Net.Rest/API/Common/GuildApplicationCommandPermissions.cs
+++ b/src/Discord.Net.Rest/API/Common/GuildApplicationCommandPermissions.cs
@@ -1,9 +1,4 @@
using Newtonsoft.Json;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
namespace Discord.API
{
@@ -19,6 +14,6 @@ namespace Discord.API
public ulong GuildId { get; set; }
[JsonProperty("permissions")]
- public API.ApplicationCommandPermissions[] Permissions { get; set; }
+ public ApplicationCommandPermissions[] Permissions { get; set; }
}
}
diff --git a/src/Discord.Net.Rest/API/Common/Interaction.cs b/src/Discord.Net.Rest/API/Common/Interaction.cs
index ebbc5fc1b..7f953384d 100644
--- a/src/Discord.Net.Rest/API/Common/Interaction.cs
+++ b/src/Discord.Net.Rest/API/Common/Interaction.cs
@@ -1,9 +1,4 @@
using Newtonsoft.Json;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
namespace Discord.API
{
diff --git a/src/Discord.Net.Rest/API/Common/InteractionCallbackData.cs b/src/Discord.Net.Rest/API/Common/InteractionCallbackData.cs
index 38b35c8ec..b07ebff49 100644
--- a/src/Discord.Net.Rest/API/Common/InteractionCallbackData.cs
+++ b/src/Discord.Net.Rest/API/Common/InteractionCallbackData.cs
@@ -11,7 +11,7 @@ namespace Discord.API
public Optional Content { get; set; }
[JsonProperty("embeds")]
- public Optional Embeds { get; set; }
+ public Optional
public override Task AddPermissionOverwriteAsync(IRole role, OverwritePermissions permissions, RequestOptions options = null)
- => throw new NotImplementedException();
+ => throw new NotSupportedException("This method is not supported in threads.");
///
///
/// This method is not supported in threads.
///
public override Task AddPermissionOverwriteAsync(IUser user, OverwritePermissions permissions, RequestOptions options = null)
- => throw new NotImplementedException();
+ => throw new NotSupportedException("This method is not supported in threads.");
///
///
/// This method is not supported in threads.
///
public override Task CreateInviteAsync(int? maxAge = 86400, int? maxUses = null, bool isTemporary = false, bool isUnique = false, RequestOptions options = null)
- => throw new NotImplementedException();
+ => throw new NotSupportedException("This method is not supported in threads.");
///
///
/// This method is not supported in threads.
///
public override Task CreateInviteToApplicationAsync(ulong applicationId, int? maxAge, int? maxUses = null, bool isTemporary = false, bool isUnique = false, RequestOptions options = null)
- => throw new NotImplementedException();
+ => throw new NotSupportedException("This method is not supported in threads.");
///
///
/// This method is not supported in threads.
///
public override Task CreateInviteToStreamAsync(IUser user, int? maxAge, int? maxUses = null, bool isTemporary = false, bool isUnique = false, RequestOptions options = null)
- => throw new NotImplementedException();
+ => throw new NotSupportedException("This method is not supported in threads.");
///
///
/// This method is not supported in threads.
///
public override Task CreateWebhookAsync(string name, Stream avatar = null, RequestOptions options = null)
- => throw new NotImplementedException();
+ => throw new NotSupportedException("This method is not supported in threads.");
///
///
/// This method is not supported in threads.
///
public override Task GetCategoryAsync(RequestOptions options = null)
- => throw new NotImplementedException();
+ => throw new NotSupportedException("This method is not supported in threads.");
///
///
/// This method is not supported in threads.
///
public override Task> GetInvitesAsync(RequestOptions options = null)
- => throw new NotImplementedException();
+ => throw new NotSupportedException("This method is not supported in threads.");
///
///
/// This method is not supported in threads.
///
public override OverwritePermissions? GetPermissionOverwrite(IRole role)
- => throw new NotImplementedException();
+ => throw new NotSupportedException("This method is not supported in threads.");
///
///
/// This method is not supported in threads.
///
public override OverwritePermissions? GetPermissionOverwrite(IUser user)
- => throw new NotImplementedException();
+ => throw new NotSupportedException("This method is not supported in threads.");
///
///
/// This method is not supported in threads.
///
public override Task GetWebhookAsync(ulong id, RequestOptions options = null)
- => throw new NotImplementedException();
+ => throw new NotSupportedException("This method is not supported in threads.");
///
///
/// This method is not supported in threads.
///
public override Task> GetWebhooksAsync(RequestOptions options = null)
- => throw new NotImplementedException();
+ => throw new NotSupportedException("This method is not supported in threads.");
///
///
/// This method is not supported in threads.
///
public override Task RemovePermissionOverwriteAsync(IRole role, RequestOptions options = null)
- => throw new NotImplementedException();
+ => throw new NotSupportedException("This method is not supported in threads.");
///
///
/// This method is not supported in threads.
///
public override Task RemovePermissionOverwriteAsync(IUser user, RequestOptions options = null)
- => throw new NotImplementedException();
+ => throw new NotSupportedException("This method is not supported in threads.");
///
///
/// This method is not supported in threads.
///
public override IReadOnlyCollection PermissionOverwrites
- => throw new NotImplementedException();
+ => throw new NotSupportedException("This method is not supported in threads.");
-
///
public Task JoinAsync(RequestOptions options = null)
=> Discord.ApiClient.JoinThreadAsync(Id, options);
diff --git a/src/Discord.Net.Rest/Entities/Channels/ThreadHelper.cs b/src/Discord.Net.Rest/Entities/Channels/ThreadHelper.cs
index f1bf238bc..69eb0d768 100644
--- a/src/Discord.Net.Rest/Entities/Channels/ThreadHelper.cs
+++ b/src/Discord.Net.Rest/Entities/Channels/ThreadHelper.cs
@@ -1,8 +1,6 @@
using Discord.API.Rest;
using System;
-using System.Collections.Generic;
using System.Linq;
-using System.Text;
using System.Threading.Tasks;
using Model = Discord.API.Channel;
@@ -14,22 +12,22 @@ namespace Discord.Rest
ThreadArchiveDuration autoArchiveDuration = ThreadArchiveDuration.OneDay, IMessage message = null, RequestOptions options = null)
{
if (autoArchiveDuration == ThreadArchiveDuration.OneWeek && !channel.Guild.Features.Contains("SEVEN_DAY_THREAD_ARCHIVE"))
- throw new ArgumentException($"The guild {channel.Guild.Name} does not have the SEVEN_DAY_THREAD_ARCHIVE feature!");
+ throw new ArgumentException($"The guild {channel.Guild.Name} does not have the SEVEN_DAY_THREAD_ARCHIVE feature!", nameof(autoArchiveDuration));
if (autoArchiveDuration == ThreadArchiveDuration.ThreeDays && !channel.Guild.Features.Contains("THREE_DAY_THREAD_ARCHIVE"))
- throw new ArgumentException($"The guild {channel.Guild.Name} does not have the THREE_DAY_THREAD_ARCHIVE feature!");
+ throw new ArgumentException($"The guild {channel.Guild.Name} does not have the THREE_DAY_THREAD_ARCHIVE feature!", nameof(autoArchiveDuration));
if (type == ThreadType.PrivateThread && !channel.Guild.Features.Contains("PRIVATE_THREADS"))
- throw new ArgumentException($"The guild {channel.Guild.Name} does not have the PRIVATE_THREADS feature!");
+ throw new ArgumentException($"The guild {channel.Guild.Name} does not have the PRIVATE_THREADS feature!", nameof(type));
- var args = new StartThreadParams()
+ var args = new StartThreadParams
{
Name = name,
Duration = autoArchiveDuration,
Type = type
};
- Model model = null;
+ Model model;
if (message != null)
model = await client.ApiClient.StartThreadAsync(channel.Id, message.Id, args, options).ConfigureAwait(false);
@@ -45,7 +43,7 @@ namespace Discord.Rest
{
var args = new TextChannelProperties();
func(args);
- var apiArgs = new API.Rest.ModifyThreadParams
+ var apiArgs = new ModifyThreadParams
{
Name = args.Name,
Archived = args.Archived,
@@ -63,7 +61,7 @@ namespace Discord.Rest
return users.Select(x => RestThreadUser.Create(client, channel.Guild, x, channel)).ToArray();
}
- public static async Task GetUserAsync(ulong userdId, IThreadChannel channel, BaseDiscordClient client, RequestOptions options = null)
- => (await GetUsersAsync(channel, client, options).ConfigureAwait(false)).FirstOrDefault(x => x.Id == userdId);
+ public static async Task GetUserAsync(ulong userId, IThreadChannel channel, BaseDiscordClient client, RequestOptions options = null)
+ => (await GetUsersAsync(channel, client, options).ConfigureAwait(false)).FirstOrDefault(x => x.Id == userId);
}
}
diff --git a/src/Discord.Net.Rest/Entities/Guilds/RestGuild.cs b/src/Discord.Net.Rest/Entities/Guilds/RestGuild.cs
index 7a14fa9df..8b0659baf 100644
--- a/src/Discord.Net.Rest/Entities/Guilds/RestGuild.cs
+++ b/src/Discord.Net.Rest/Entities/Guilds/RestGuild.cs
@@ -922,7 +922,7 @@ namespace Discord.Rest
/// of application commands found within the guild.
///
public async Task> GetApplicationCommandsAsync (RequestOptions options = null)
- => await ClientHelper.GetGuildApplicationCommands(Discord, Id, options).ConfigureAwait(false);
+ => await ClientHelper.GetGuildApplicationCommandsAsync(Discord, Id, options).ConfigureAwait(false);
///
/// Gets an application command within this guild with the specified id.
///
@@ -933,7 +933,7 @@ namespace Discord.Rest
/// if found, otherwise .
///
public async Task GetApplicationCommandAsync(ulong id, RequestOptions options = null)
- => await ClientHelper.GetGuildApplicationCommand(Discord, id, Id, options);
+ => await ClientHelper.GetGuildApplicationCommandAsync(Discord, id, Id, options);
///
/// Creates an application command within this guild.
///
@@ -944,7 +944,7 @@ namespace Discord.Rest
///
public async Task CreateApplicationCommandAsync(ApplicationCommandProperties properties, RequestOptions options = null)
{
- var model = await InteractionHelper.CreateGuildCommand(Discord, Id, properties, options);
+ var model = await InteractionHelper.CreateGuildCommandAsync(Discord, Id, properties, options);
return RestGuildCommand.Create(Discord, model, Id);
}
@@ -959,7 +959,7 @@ namespace Discord.Rest
public async Task> BulkOverwriteApplicationCommandsAsync(ApplicationCommandProperties[] properties,
RequestOptions options = null)
{
- var models = await InteractionHelper.BulkOverwriteGuildCommands(Discord, Id, properties, options);
+ var models = await InteractionHelper.BulkOverwriteGuildCommandsAsync(Discord, Id, properties, options);
return models.Select(x => RestGuildCommand.Create(Discord, x, Id)).ToImmutableArray();
}
diff --git a/src/Discord.Net.Rest/Entities/Interactions/InteractionHelper.cs b/src/Discord.Net.Rest/Entities/Interactions/InteractionHelper.cs
index 760fc8300..f1b1e67bd 100644
--- a/src/Discord.Net.Rest/Entities/Interactions/InteractionHelper.cs
+++ b/src/Discord.Net.Rest/Entities/Interactions/InteractionHelper.cs
@@ -4,6 +4,7 @@ using Discord.Net;
using System;
using System.Collections.Generic;
using System.Linq;
+using System.Net;
using System.Threading.Tasks;
namespace Discord.Rest
@@ -13,15 +14,15 @@ namespace Discord.Rest
#region InteractionHelper
public static Task DeleteAllGuildCommandsAsync(BaseDiscordClient client, ulong guildId, RequestOptions options = null)
{
- return client.ApiClient.BulkOverwriteGuildApplicationCommandsAsync(guildId, new CreateApplicationCommandParams[0], options);
+ return client.ApiClient.BulkOverwriteGuildApplicationCommandsAsync(guildId, Array.Empty(), options);
}
public static Task DeleteAllGlobalCommandsAsync(BaseDiscordClient client, RequestOptions options = null)
{
- return client.ApiClient.BulkOverwriteGlobalApplicationCommandsAsync(new CreateApplicationCommandParams[0], options);
+ return client.ApiClient.BulkOverwriteGlobalApplicationCommandsAsync(Array.Empty(), options);
}
- public static Task SendInteractionResponse(BaseDiscordClient client, InteractionResponse response,
+ public static Task SendInteractionResponseAsync(BaseDiscordClient client, InteractionResponse response,
ulong interactionId, string interactionToken, RequestOptions options = null)
{
return client.ApiClient.CreateInteractionResponseAsync(response, interactionId, interactionToken, options);
@@ -39,7 +40,7 @@ namespace Discord.Rest
{
var model = await client.ApiClient.CreateInteractionFollowupMessageAsync(args, token, options).ConfigureAwait(false);
- RestFollowupMessage entity = RestFollowupMessage.Create(client, model, token, channel);
+ var entity = RestFollowupMessage.Create(client, model, token, channel);
return entity;
}
#endregion
@@ -50,22 +51,21 @@ namespace Discord.Rest
{
var model = await client.ApiClient.GetGlobalApplicationCommandAsync(id, options).ConfigureAwait(false);
-
return RestGlobalCommand.Create(client, model);
}
- public static Task CreateGlobalCommand(BaseDiscordClient client,
+ public static Task CreateGlobalCommandAsync(BaseDiscordClient client,
Action func, RequestOptions options = null) where TArg : ApplicationCommandProperties
{
var args = Activator.CreateInstance(typeof(TArg));
func((TArg)args);
- return CreateGlobalCommand(client, (TArg)args, options);
+ return CreateGlobalCommandAsync(client, (TArg)args, options);
}
- public static async Task CreateGlobalCommand(BaseDiscordClient client,
+ public static async Task CreateGlobalCommandAsync(BaseDiscordClient client,
ApplicationCommandProperties arg, RequestOptions options = null)
{
Preconditions.NotNullOrEmpty(arg.Name, nameof(arg.Name));
- var model = new CreateApplicationCommandParams()
+ var model = new CreateApplicationCommandParams
{
Name = arg.Name.Value,
Type = arg.Type,
@@ -81,25 +81,25 @@ namespace Discord.Rest
model.Description = slashProps.Description.Value;
model.Options = slashProps.Options.IsSpecified
- ? slashProps.Options.Value.Select(x => new Discord.API.ApplicationCommandOption(x)).ToArray()
- : Optional.Unspecified;
+ ? slashProps.Options.Value.Select(x => new ApplicationCommandOption(x)).ToArray()
+ : Optional.Unspecified;
}
return await client.ApiClient.CreateGlobalApplicationCommandAsync(model, options).ConfigureAwait(false);
}
- public static async Task BulkOverwriteGlobalCommands(BaseDiscordClient client,
+ public static async Task BulkOverwriteGlobalCommandsAsync(BaseDiscordClient client,
ApplicationCommandProperties[] args, RequestOptions options = null)
{
Preconditions.NotNull(args, nameof(args));
- List models = new List();
+ var models = new List();
foreach (var arg in args)
{
Preconditions.NotNullOrEmpty(arg.Name, nameof(arg.Name));
- var model = new CreateApplicationCommandParams()
+ var model = new CreateApplicationCommandParams
{
Name = arg.Name.Value,
Type = arg.Type,
@@ -115,28 +115,28 @@ namespace Discord.Rest
model.Description = slashProps.Description.Value;
model.Options = slashProps.Options.IsSpecified
- ? slashProps.Options.Value.Select(x => new Discord.API.ApplicationCommandOption(x)).ToArray()
- : Optional.Unspecified;
+ ? slashProps.Options.Value.Select(x => new ApplicationCommandOption(x)).ToArray()
+ : Optional.Unspecified;
}
models.Add(model);
}
- return await client.ApiClient.BulkOverwriteGlobalApplicationCommandsAsync(models.ToArray(), options).ConfigureAwait(false);
+ return await client.ApiClient.BulkOverwriteGlobalApplicationCommandsAsync(models.ToArray(), options).ConfigureAwait(false);
}
- public static async Task> BulkOverwriteGuildCommands(BaseDiscordClient client, ulong guildId,
+ public static async Task> BulkOverwriteGuildCommandsAsync(BaseDiscordClient client, ulong guildId,
ApplicationCommandProperties[] args, RequestOptions options = null)
{
Preconditions.NotNull(args, nameof(args));
- List models = new List();
+ var models = new List();
foreach (var arg in args)
{
Preconditions.NotNullOrEmpty(arg.Name, nameof(arg.Name));
- var model = new CreateApplicationCommandParams()
+ var model = new CreateApplicationCommandParams
{
Name = arg.Name.Value,
Type = arg.Type,
@@ -152,8 +152,8 @@ namespace Discord.Rest
model.Description = slashProps.Description.Value;
model.Options = slashProps.Options.IsSpecified
- ? slashProps.Options.Value.Select(x => new Discord.API.ApplicationCommandOption(x)).ToArray()
- : Optional.Unspecified;
+ ? slashProps.Options.Value.Select(x => new ApplicationCommandOption(x)).ToArray()
+ : Optional.Unspecified;
}
models.Add(model);
@@ -180,15 +180,15 @@ namespace Discord.Rest
}
}
- public static Task ModifyGlobalCommand(BaseDiscordClient client, IApplicationCommand command,
+ public static Task ModifyGlobalCommandAsync(BaseDiscordClient client, IApplicationCommand command,
Action func, RequestOptions options = null) where TArg : ApplicationCommandProperties
{
var arg = GetApplicationCommandProperties(command);
func(arg);
- return ModifyGlobalCommand(client, command, arg, options);
+ return ModifyGlobalCommandAsync(client, command, arg, options);
}
- public static async Task ModifyGlobalCommand(BaseDiscordClient client, IApplicationCommand command,
+ public static async Task ModifyGlobalCommandAsync(BaseDiscordClient client, IApplicationCommand command,
ApplicationCommandProperties args, RequestOptions options = null)
{
if (args.Name.IsSpecified)
@@ -197,7 +197,7 @@ namespace Discord.Rest
Preconditions.AtLeast(args.Name.Value.Length, 1, nameof(args.Name));
}
- var model = new Discord.API.Rest.ModifyApplicationCommandParams()
+ var model = new ModifyApplicationCommandParams
{
Name = args.Name,
DefaultPermission = args.DefaultPermission.IsSpecified
@@ -205,7 +205,7 @@ namespace Discord.Rest
: Optional.Unspecified
};
- if(args is SlashCommandProperties slashProps)
+ if (args is SlashCommandProperties slashProps)
{
if (slashProps.Description.IsSpecified)
{
@@ -222,15 +222,14 @@ namespace Discord.Rest
model.Description = slashProps.Description;
model.Options = slashProps.Options.IsSpecified
- ? slashProps.Options.Value.Select(x => new Discord.API.ApplicationCommandOption(x)).ToArray()
- : Optional.Unspecified;
+ ? slashProps.Options.Value.Select(x => new ApplicationCommandOption(x)).ToArray()
+ : Optional.Unspecified;
}
return await client.ApiClient.ModifyGlobalApplicationCommandAsync(model, command.Id, options).ConfigureAwait(false);
}
-
- public static async Task DeleteGlobalCommand(BaseDiscordClient client, IApplicationCommand command, RequestOptions options = null)
+ public static async Task DeleteGlobalCommandAsync(BaseDiscordClient client, IApplicationCommand command, RequestOptions options = null)
{
Preconditions.NotNull(command, nameof(command));
Preconditions.NotEqual(command.Id, 0, nameof(command.Id));
@@ -240,18 +239,18 @@ namespace Discord.Rest
#endregion
#region Guild Commands
- public static Task CreateGuildCommand(BaseDiscordClient client, ulong guildId,
+ public static Task CreateGuildCommandAsync(BaseDiscordClient client, ulong guildId,
Action func, RequestOptions options) where TArg : ApplicationCommandProperties
{
var args = Activator.CreateInstance(typeof(TArg));
func((TArg)args);
- return CreateGuildCommand(client, guildId, (TArg)args, options);
+ return CreateGuildCommandAsync(client, guildId, (TArg)args, options);
}
- public static async Task CreateGuildCommand(BaseDiscordClient client, ulong guildId,
+ public static async Task CreateGuildCommandAsync(BaseDiscordClient client, ulong guildId,
ApplicationCommandProperties arg, RequestOptions options = null)
{
- var model = new CreateApplicationCommandParams()
+ var model = new CreateApplicationCommandParams
{
Name = arg.Name.Value,
Type = arg.Type,
@@ -267,25 +266,25 @@ namespace Discord.Rest
model.Description = slashProps.Description.Value;
model.Options = slashProps.Options.IsSpecified
- ? slashProps.Options.Value.Select(x => new Discord.API.ApplicationCommandOption(x)).ToArray()
- : Optional.Unspecified;
+ ? slashProps.Options.Value.Select(x => new ApplicationCommandOption(x)).ToArray()
+ : Optional.Unspecified;
}
return await client.ApiClient.CreateGuildApplicationCommandAsync(model, guildId, options).ConfigureAwait(false);
}
- public static Task ModifyGuildCommand(BaseDiscordClient client, IApplicationCommand command, ulong guildId,
+ public static Task ModifyGuildCommandAsync(BaseDiscordClient client, IApplicationCommand command, ulong guildId,
Action func, RequestOptions options = null) where TArg : ApplicationCommandProperties
{
var arg = GetApplicationCommandProperties(command);
func(arg);
- return ModifyGuildCommand(client, command, guildId, arg, options);
+ return ModifyGuildCommandAsync(client, command, guildId, arg, options);
}
- public static async Task ModifyGuildCommand(BaseDiscordClient client, IApplicationCommand command, ulong guildId,
+ public static async Task ModifyGuildCommandAsync(BaseDiscordClient client, IApplicationCommand command, ulong guildId,
ApplicationCommandProperties arg, RequestOptions options = null)
{
- var model = new ModifyApplicationCommandParams()
+ var model = new ModifyApplicationCommandParams
{
Name = arg.Name,
DefaultPermission = arg.DefaultPermission.IsSpecified
@@ -300,14 +299,14 @@ namespace Discord.Rest
model.Description = slashProps.Description.Value;
model.Options = slashProps.Options.IsSpecified
- ? slashProps.Options.Value.Select(x => new Discord.API.ApplicationCommandOption(x)).ToArray()
- : Optional.Unspecified;
+ ? slashProps.Options.Value.Select(x => new ApplicationCommandOption(x)).ToArray()
+ : Optional.Unspecified;
}
return await client.ApiClient.ModifyGuildApplicationCommandAsync(model, guildId, command.Id, options).ConfigureAwait(false);
}
- public static async Task DeleteGuildCommand(BaseDiscordClient client, ulong guildId, IApplicationCommand command, RequestOptions options = null)
+ public static async Task DeleteGuildCommandAsync(BaseDiscordClient client, ulong guildId, IApplicationCommand command, RequestOptions options = null)
{
Preconditions.NotNull(command, nameof(command));
Preconditions.NotEqual(command.Id, 0, nameof(command.Id));
@@ -315,21 +314,16 @@ namespace Discord.Rest
await client.ApiClient.DeleteGuildApplicationCommandAsync(guildId, command.Id, options).ConfigureAwait(false);
}
- public static Task DeleteUnknownApplicationCommand(BaseDiscordClient client, ulong? guildId, IApplicationCommand command, RequestOptions options = null)
+ public static Task DeleteUnknownApplicationCommandAsync(BaseDiscordClient client, ulong? guildId, IApplicationCommand command, RequestOptions options = null)
{
- if (guildId.HasValue)
- {
- return DeleteGuildCommand(client, guildId.Value, command, options);
- }
- else
- {
- return DeleteGlobalCommand(client, command, options);
- }
+ return guildId.HasValue
+ ? DeleteGuildCommandAsync(client, guildId.Value, command, options)
+ : DeleteGlobalCommandAsync(client, command, options);
}
#endregion
#region Responses
- public static async Task ModifyFollowupMessage(BaseDiscordClient client, RestFollowupMessage message, Action func,
+ public static async Task ModifyFollowupMessageAsync(BaseDiscordClient client, RestFollowupMessage message, Action func,
RequestOptions options = null)
{
var args = new MessageProperties();
@@ -359,21 +353,19 @@ namespace Discord.Rest
Preconditions.AtMost(apiEmbeds?.Count ?? 0, 10, nameof(args.Embeds), "A max of 10 embeds are allowed.");
- var apiArgs = new API.Rest.ModifyInteractionResponseParams
+ var apiArgs = new ModifyInteractionResponseParams
{
Content = args.Content,
Embeds = apiEmbeds?.ToArray() ?? Optional.Unspecified,
AllowedMentions = args.AllowedMentions.IsSpecified ? args.AllowedMentions.Value.ToModel() : Optional.Unspecified,
- Components = args.Components.IsSpecified ? args.Components.Value?.Components.Select(x => new API.ActionRowComponent(x)).ToArray() : Optional.Unspecified,
+ Components = args.Components.IsSpecified ? args.Components.Value?.Components.Select(x => new API.ActionRowComponent(x)).ToArray() : Optional.Unspecified
};
return await client.ApiClient.ModifyInteractionFollowupMessageAsync(apiArgs, message.Id, message.Token, options).ConfigureAwait(false);
}
-
- public static async Task DeleteFollowupMessage(BaseDiscordClient client, RestFollowupMessage message, RequestOptions options = null)
+ public static async Task DeleteFollowupMessageAsync(BaseDiscordClient client, RestFollowupMessage message, RequestOptions options = null)
=> await client.ApiClient.DeleteInteractionFollowupMessageAsync(message.Id, message.Token, options);
-
- public static async Task ModifyInteractionResponse(BaseDiscordClient client, string token, Action func,
+ public static async Task ModifyInteractionResponseAsync(BaseDiscordClient client, string token, Action func,
RequestOptions options = null)
{
var args = new MessageProperties();
@@ -415,25 +407,24 @@ namespace Discord.Rest
return await client.ApiClient.ModifyInteractionResponseAsync(apiArgs, token, options).ConfigureAwait(false);
}
- public static async Task DeletedInteractionResponse(BaseDiscordClient client, RestInteractionMessage message, RequestOptions options = null)
+ public static async Task DeleteInteractionResponseAsync(BaseDiscordClient client, RestInteractionMessage message, RequestOptions options = null)
=> await client.ApiClient.DeleteInteractionFollowupMessageAsync(message.Id, message.Token, options);
- public static Task SendAutocompleteResult(BaseDiscordClient client, IEnumerable result, ulong interactionId,
+ public static Task SendAutocompleteResultAsync(BaseDiscordClient client, IEnumerable result, ulong interactionId,
string interactionToken, RequestOptions options)
{
- if (result == null)
- result = new AutocompleteResult[0];
+ result ??= Array.Empty();
Preconditions.AtMost(result.Count(), 20, nameof(result), "A maximum of 20 choices are allowed!");
- var apiArgs = new InteractionResponse()
+ var apiArgs = new InteractionResponse
{
Type = InteractionResponseType.ApplicationCommandAutocompleteResult,
- Data = new InteractionCallbackData()
+ Data = new InteractionCallbackData
{
Choices = result.Any()
- ? result.Select(x => new API.ApplicationCommandOptionChoice() { Name = x.Name, Value = x.Value }).ToArray()
- : new ApplicationCommandOptionChoice[0]
+ ? result.Select(x => new ApplicationCommandOptionChoice { Name = x.Name, Value = x.Value }).ToArray()
+ : Array.Empty()
}
};
@@ -448,7 +439,7 @@ namespace Discord.Rest
var models = await client.ApiClient.GetGuildApplicationCommandPermissionsAsync(guildId, options);
return models.Select(x =>
new GuildApplicationCommandPermission(x.Id, x.ApplicationId, guildId, x.Permissions.Select(
- y => new Discord.ApplicationCommandPermission(y.Id, y.Type, y.Permission))
+ y => new ApplicationCommandPermission(y.Id, y.Type, y.Permission))
.ToArray())
).ToArray();
}
@@ -464,7 +455,7 @@ namespace Discord.Rest
}
catch (HttpException x)
{
- if (x.HttpCode == System.Net.HttpStatusCode.NotFound)
+ if (x.HttpCode == HttpStatusCode.NotFound)
return null;
throw;
}
@@ -477,11 +468,11 @@ namespace Discord.Rest
Preconditions.AtMost(args.Length, 10, nameof(args));
Preconditions.AtLeast(args.Length, 0, nameof(args));
- List permissionsList = new List();
+ var permissionsList = new List();
foreach (var arg in args)
{
- var permissions = new ApplicationCommandPermissions()
+ var permissions = new ApplicationCommandPermissions
{
Id = arg.TargetId,
Permission = arg.Permission,
@@ -491,7 +482,7 @@ namespace Discord.Rest
permissionsList.Add(permissions);
}
- ModifyGuildApplicationCommandPermissionsParams model = new ModifyGuildApplicationCommandPermissionsParams()
+ var model = new ModifyGuildApplicationCommandPermissionsParams
{
Permissions = permissionsList.ToArray()
};
@@ -508,16 +499,16 @@ namespace Discord.Rest
Preconditions.NotNull(args, nameof(args));
Preconditions.NotEqual(args.Count, 0, nameof(args));
- List models = new List();
+ var models = new List();
foreach (var arg in args)
{
Preconditions.AtMost(arg.Value.Length, 10, nameof(args));
- var model = new ModifyGuildApplicationCommandPermissions()
+ var model = new ModifyGuildApplicationCommandPermissions
{
Id = arg.Key,
- Permissions = arg.Value.Select(x => new ApplicationCommandPermissions()
+ Permissions = arg.Value.Select(x => new ApplicationCommandPermissions
{
Id = x.TargetId,
Permission = x.Permission,
diff --git a/src/Discord.Net.Rest/Entities/Interactions/RestApplicationCommand.cs b/src/Discord.Net.Rest/Entities/Interactions/RestApplicationCommand.cs
index 0ef365eb7..c3edaf6ff 100644
--- a/src/Discord.Net.Rest/Entities/Interactions/RestApplicationCommand.cs
+++ b/src/Discord.Net.Rest/Entities/Interactions/RestApplicationCommand.cs
@@ -2,7 +2,6 @@ using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
-using System.Text;
using System.Threading.Tasks;
using Model = Discord.API.ApplicationCommand;
@@ -38,21 +37,13 @@ namespace Discord.Rest
=> SnowflakeUtils.FromSnowflake(Id);
internal RestApplicationCommand(BaseDiscordClient client, ulong id)
- : base(client, id)
- {
-
- }
+ : base(client, id) { }
internal static RestApplicationCommand Create(BaseDiscordClient client, Model model, ulong? guildId)
{
- if (guildId.HasValue)
- {
- return RestGuildCommand.Create(client, model, guildId.Value);
- }
- else
- {
- return RestGlobalCommand.Create(client, model);
- }
+ return guildId.HasValue
+ ? RestGuildCommand.Create(client, model, guildId.Value)
+ : RestGlobalCommand.Create(client, model);
}
internal virtual void Update(Model model)
@@ -64,7 +55,7 @@ namespace Discord.Rest
IsDefaultPermission = model.DefaultPermissions.GetValueOrDefault(true);
Options = model.Options.IsSpecified
- ? model.Options.Value.Select(x => RestApplicationCommandOption.Create(x)).ToImmutableArray()
+ ? model.Options.Value.Select(RestApplicationCommandOption.Create).ToImmutableArray()
: ImmutableArray.Create();
}
@@ -76,7 +67,7 @@ namespace Discord.Rest
{
return ModifyAsync(func, options);
}
-
+
///
public abstract Task ModifyAsync(Action func, RequestOptions options = null)
where TArg : ApplicationCommandProperties;
diff --git a/src/Discord.Net.Rest/Entities/Interactions/RestApplicationCommandChoice.cs b/src/Discord.Net.Rest/Entities/Interactions/RestApplicationCommandChoice.cs
index cd1f73768..a40491a2c 100644
--- a/src/Discord.Net.Rest/Entities/Interactions/RestApplicationCommandChoice.cs
+++ b/src/Discord.Net.Rest/Entities/Interactions/RestApplicationCommandChoice.cs
@@ -1,8 +1,3 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
using Model = Discord.API.ApplicationCommandOptionChoice;
namespace Discord.Rest
diff --git a/src/Discord.Net.Rest/Entities/Interactions/RestApplicationCommandOption.cs b/src/Discord.Net.Rest/Entities/Interactions/RestApplicationCommandOption.cs
index f3487ae67..460ff872a 100644
--- a/src/Discord.Net.Rest/Entities/Interactions/RestApplicationCommandOption.cs
+++ b/src/Discord.Net.Rest/Entities/Interactions/RestApplicationCommandOption.cs
@@ -1,9 +1,6 @@
-using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
using Model = Discord.API.ApplicationCommandOption;
namespace Discord.Rest
@@ -66,7 +63,7 @@ namespace Discord.Rest
IsRequired = model.Required.Value;
Options = model.Options.IsSpecified
- ? model.Options.Value.Select(x => Create(x)).ToImmutableArray()
+ ? model.Options.Value.Select(Create).ToImmutableArray()
: ImmutableArray.Create();
Choices = model.Choices.IsSpecified
diff --git a/src/Discord.Net.Rest/Entities/Interactions/RestGlobalCommand.cs b/src/Discord.Net.Rest/Entities/Interactions/RestGlobalCommand.cs
index bee1f39cd..c319bcf34 100644
--- a/src/Discord.Net.Rest/Entities/Interactions/RestGlobalCommand.cs
+++ b/src/Discord.Net.Rest/Entities/Interactions/RestGlobalCommand.cs
@@ -1,7 +1,4 @@
using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
using System.Threading.Tasks;
using Model = Discord.API.ApplicationCommand;
@@ -13,10 +10,7 @@ namespace Discord.Rest
public class RestGlobalCommand : RestApplicationCommand
{
internal RestGlobalCommand(BaseDiscordClient client, ulong id)
- : base(client, id)
- {
-
- }
+ : base(client, id) { }
internal static RestGlobalCommand Create(BaseDiscordClient client, Model model)
{
@@ -27,7 +21,7 @@ namespace Discord.Rest
///
public override async Task DeleteAsync(RequestOptions options = null)
- => await InteractionHelper.DeleteGlobalCommand(Discord, this).ConfigureAwait(false);
+ => await InteractionHelper.DeleteGlobalCommandAsync(Discord, this).ConfigureAwait(false);
///
/// Modifies this .
@@ -39,7 +33,7 @@ namespace Discord.Rest
///
public override async Task ModifyAsync(Action func, RequestOptions options = null)
{
- var cmd = await InteractionHelper.ModifyGlobalCommand(Discord, this, func, options).ConfigureAwait(false);
+ var cmd = await InteractionHelper.ModifyGlobalCommandAsync(Discord, this, func, options).ConfigureAwait(false);
Update(cmd);
}
}
diff --git a/src/Discord.Net.Rest/Entities/Interactions/RestGuildCommand.cs b/src/Discord.Net.Rest/Entities/Interactions/RestGuildCommand.cs
index fb41c1812..00804e57e 100644
--- a/src/Discord.Net.Rest/Entities/Interactions/RestGuildCommand.cs
+++ b/src/Discord.Net.Rest/Entities/Interactions/RestGuildCommand.cs
@@ -1,7 +1,4 @@
using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
using System.Threading.Tasks;
using Model = Discord.API.ApplicationCommand;
@@ -32,7 +29,7 @@ namespace Discord.Rest
///
public override async Task DeleteAsync(RequestOptions options = null)
- => await InteractionHelper.DeleteGuildCommand(Discord, GuildId, this).ConfigureAwait(false);
+ => await InteractionHelper.DeleteGuildCommandAsync(Discord, GuildId, this).ConfigureAwait(false);
///
/// Modifies this .
@@ -44,7 +41,7 @@ namespace Discord.Rest
///
public override async Task ModifyAsync(Action func, RequestOptions options = null)
{
- var model = await InteractionHelper.ModifyGuildCommand(Discord, this, GuildId, func, options).ConfigureAwait(false);
+ var model = await InteractionHelper.ModifyGuildCommandAsync(Discord, this, GuildId, func, options).ConfigureAwait(false);
Update(model);
}
diff --git a/src/Discord.Net.Rest/Entities/Messages/CustomSticker.cs b/src/Discord.Net.Rest/Entities/Messages/CustomSticker.cs
index e0d3900fa..6fd0f7700 100644
--- a/src/Discord.Net.Rest/Entities/Messages/CustomSticker.cs
+++ b/src/Discord.Net.Rest/Entities/Messages/CustomSticker.cs
@@ -1,8 +1,5 @@
using System;
-using System.Collections.Generic;
using System.Diagnostics;
-using System.Linq;
-using System.Text;
using System.Threading.Tasks;
using Model = Discord.API.Sticker;
diff --git a/src/Discord.Net.Rest/Entities/Messages/MessageHelper.cs b/src/Discord.Net.Rest/Entities/Messages/MessageHelper.cs
index 8de9ccf32..01a861cc5 100644
--- a/src/Discord.Net.Rest/Entities/Messages/MessageHelper.cs
+++ b/src/Discord.Net.Rest/Entities/Messages/MessageHelper.cs
@@ -84,7 +84,7 @@ namespace Discord.Rest
{
Content = args.Content,
Embeds = apiEmbeds?.ToArray() ?? Optional.Unspecified,
- Components = args.Components.IsSpecified ? args.Components.Value?.Components.Select(x => new API.ActionRowComponent(x)).ToArray() ?? new API.ActionRowComponent[0] : Optional.Unspecified,
+ Components = args.Components.IsSpecified ? args.Components.Value?.Components.Select(x => new API.ActionRowComponent(x)).ToArray() ?? Array.Empty() : Optional.Unspecified,
Flags = args.Flags,
AllowedMentions = args.AllowedMentions.IsSpecified ? args.AllowedMentions.Value.ToModel() : Optional.Unspecified,
};
@@ -151,7 +151,7 @@ namespace Discord.Rest
Embeds = apiEmbeds?.ToArray() ?? Optional.Unspecified,
Flags = args.Flags.IsSpecified ? args.Flags.Value : Optional.Create(),
AllowedMentions = args.AllowedMentions.IsSpecified ? args.AllowedMentions.Value.ToModel() : Optional.Create(),
- Components = args.Components.IsSpecified ? args.Components.Value?.Components.Select(x => new API.ActionRowComponent(x)).ToArray() ?? new API.ActionRowComponent[0] : Optional.Unspecified,
+ Components = args.Components.IsSpecified ? args.Components.Value?.Components.Select(x => new API.ActionRowComponent(x)).ToArray() ?? Array.Empty() : Optional.Unspecified,
};
return await client.ApiClient.ModifyMessageAsync(channelId, msgId, apiArgs, options).ConfigureAwait(false);
}
diff --git a/src/Discord.Net.Rest/Entities/Messages/RestFollowupMessage.cs b/src/Discord.Net.Rest/Entities/Messages/RestFollowupMessage.cs
index f1a03a384..693d36e56 100644
--- a/src/Discord.Net.Rest/Entities/Messages/RestFollowupMessage.cs
+++ b/src/Discord.Net.Rest/Entities/Messages/RestFollowupMessage.cs
@@ -1,11 +1,7 @@
using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
using System.Threading.Tasks;
using Model = Discord.API.Message;
-
namespace Discord.Rest
{
///
@@ -39,7 +35,7 @@ namespace Discord.Rest
///
/// A task that represents the asynchronous delete operation.
public Task DeleteAsync()
- => InteractionHelper.DeleteFollowupMessage(Discord, this);
+ => InteractionHelper.DeleteFollowupMessageAsync(Discord, this);
///
/// Modifies this interaction followup message.
@@ -65,12 +61,12 @@ namespace Discord.Rest
{
try
{
- var model = await InteractionHelper.ModifyFollowupMessage(Discord, this, func, options).ConfigureAwait(false);
+ var model = await InteractionHelper.ModifyFollowupMessageAsync(Discord, this, func, options).ConfigureAwait(false);
Update(model);
}
- catch (Discord.Net.HttpException x)
+ catch (Net.HttpException x)
{
- if(x.HttpCode == System.Net.HttpStatusCode.NotFound)
+ if (x.HttpCode == System.Net.HttpStatusCode.NotFound)
{
throw new InvalidOperationException("The token of this message has expired!", x);
}
diff --git a/src/Discord.Net.Rest/Entities/Messages/RestInteractionMessage.cs b/src/Discord.Net.Rest/Entities/Messages/RestInteractionMessage.cs
index 51fc19483..26beb03b6 100644
--- a/src/Discord.Net.Rest/Entities/Messages/RestInteractionMessage.cs
+++ b/src/Discord.Net.Rest/Entities/Messages/RestInteractionMessage.cs
@@ -35,7 +35,7 @@ namespace Discord.Rest
///
/// A task that represents the asynchronous delete operation.
public Task DeleteAsync()
- => InteractionHelper.DeletedInteractionResponse(Discord, this);
+ => InteractionHelper.DeleteInteractionResponseAsync(Discord, this);
///
/// Modifies this interaction response
@@ -61,10 +61,10 @@ namespace Discord.Rest
{
try
{
- var model = await InteractionHelper.ModifyInteractionResponse(Discord, Token, func, options).ConfigureAwait(false);
+ var model = await InteractionHelper.ModifyInteractionResponseAsync(Discord, Token, func, options).ConfigureAwait(false);
Update(model);
}
- catch (Discord.Net.HttpException x)
+ catch (Net.HttpException x)
{
if (x.HttpCode == System.Net.HttpStatusCode.NotFound)
{
diff --git a/src/Discord.Net.Rest/Entities/Messages/Sticker.cs b/src/Discord.Net.Rest/Entities/Messages/Sticker.cs
index 75bc9bd38..accdbe66a 100644
--- a/src/Discord.Net.Rest/Entities/Messages/Sticker.cs
+++ b/src/Discord.Net.Rest/Entities/Messages/Sticker.cs
@@ -1,3 +1,4 @@
+using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
@@ -43,8 +44,8 @@ namespace Discord.Rest
{
PackId = model.PackId;
Name = model.Name;
- Description = model.Desription;
- Tags = model.Tags.IsSpecified ? model.Tags.Value.Split(',').Select(x => x.Trim()).ToArray() : new string[0];
+ Description = model.Description;
+ Tags = model.Tags.IsSpecified ? model.Tags.Value.Split(',').Select(x => x.Trim()).ToArray() : Array.Empty();
Type = model.Type;
SortOrder = model.SortValue;
IsAvailable = model.Available;
diff --git a/src/Discord.Net.Rest/Entities/Messages/StickerItem.cs b/src/Discord.Net.Rest/Entities/Messages/StickerItem.cs
index f1bcb9951..0ce4f634b 100644
--- a/src/Discord.Net.Rest/Entities/Messages/StickerItem.cs
+++ b/src/Discord.Net.Rest/Entities/Messages/StickerItem.cs
@@ -1,7 +1,3 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
using System.Threading.Tasks;
using Model = Discord.API.StickerItem;
@@ -31,15 +27,13 @@ namespace Discord.Rest
///
/// A task representing the download operation, the result of the task is a sticker object.
///
-
public async Task ResolveStickerAsync()
{
var model = await Discord.ApiClient.GetStickerAsync(Id);
- if (model.GuildId.IsSpecified)
- return CustomSticker.Create(Discord, model, model.GuildId.Value, model.User.IsSpecified ? model.User.Value.Id : null);
- else
- return Sticker.Create(Discord, model);
+ return model.GuildId.IsSpecified
+ ? CustomSticker.Create(Discord, model, model.GuildId.Value, model.User.IsSpecified ? model.User.Value.Id : null)
+ : Sticker.Create(Discord, model);
}
}
}
diff --git a/src/Discord.Net.Rest/Entities/Users/RestThreadUser.cs b/src/Discord.Net.Rest/Entities/Users/RestThreadUser.cs
index 4dd7f7aaf..82830dafd 100644
--- a/src/Discord.Net.Rest/Entities/Users/RestThreadUser.cs
+++ b/src/Discord.Net.Rest/Entities/Users/RestThreadUser.cs
@@ -1,8 +1,4 @@
using System;
-using System.Collections.Generic;
-using System.Collections.Immutable;
-using System.Linq;
-using System.Text;
using System.Threading.Tasks;
using Model = Discord.API.ThreadMember;
diff --git a/src/Discord.Net.Rest/Net/Converters/InteractionConverter.cs b/src/Discord.Net.Rest/Net/Converters/InteractionConverter.cs
index 8159165c9..ca8214682 100644
--- a/src/Discord.Net.Rest/Net/Converters/InteractionConverter.cs
+++ b/src/Discord.Net.Rest/Net/Converters/InteractionConverter.cs
@@ -1,10 +1,6 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
namespace Discord.Net.Converters
{
diff --git a/src/Discord.Net.Rest/Net/Converters/MessageComponentConverter.cs b/src/Discord.Net.Rest/Net/Converters/MessageComponentConverter.cs
index 2203008d6..0bf11a369 100644
--- a/src/Discord.Net.Rest/Net/Converters/MessageComponentConverter.cs
+++ b/src/Discord.Net.Rest/Net/Converters/MessageComponentConverter.cs
@@ -1,10 +1,6 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
namespace Discord.Net.Converters
{
diff --git a/src/Discord.Net.WebSocket/API/Gateway/ApplicationCommandCreatedUpdatedEvent.cs b/src/Discord.Net.WebSocket/API/Gateway/ApplicationCommandCreatedUpdatedEvent.cs
index 9d41ecf48..91dcbde11 100644
--- a/src/Discord.Net.WebSocket/API/Gateway/ApplicationCommandCreatedUpdatedEvent.cs
+++ b/src/Discord.Net.WebSocket/API/Gateway/ApplicationCommandCreatedUpdatedEvent.cs
@@ -1,13 +1,8 @@
using Newtonsoft.Json;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
namespace Discord.API.Gateway
{
- internal class ApplicationCommandCreatedUpdatedEvent : API.ApplicationCommand
+ internal class ApplicationCommandCreatedUpdatedEvent : ApplicationCommand
{
[JsonProperty("guild_id")]
public Optional GuildId { get; set; }
diff --git a/src/Discord.Net.WebSocket/API/Gateway/GuildStickerUpdateEvent.cs b/src/Discord.Net.WebSocket/API/Gateway/GuildStickerUpdateEvent.cs
index 8f3ba683b..f0ecd3a4f 100644
--- a/src/Discord.Net.WebSocket/API/Gateway/GuildStickerUpdateEvent.cs
+++ b/src/Discord.Net.WebSocket/API/Gateway/GuildStickerUpdateEvent.cs
@@ -1,9 +1,4 @@
using Newtonsoft.Json;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
namespace Discord.API.Gateway
{
diff --git a/src/Discord.Net.WebSocket/API/Gateway/ThreadListSyncEvent.cs b/src/Discord.Net.WebSocket/API/Gateway/ThreadListSyncEvent.cs
index ab7989268..5084f6c95 100644
--- a/src/Discord.Net.WebSocket/API/Gateway/ThreadListSyncEvent.cs
+++ b/src/Discord.Net.WebSocket/API/Gateway/ThreadListSyncEvent.cs
@@ -1,9 +1,4 @@
using Newtonsoft.Json;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
namespace Discord.API.Gateway
{
diff --git a/src/Discord.Net.WebSocket/API/Gateway/ThreadMembersUpdate.cs b/src/Discord.Net.WebSocket/API/Gateway/ThreadMembersUpdate.cs
index b6acba6ae..83d2c0edd 100644
--- a/src/Discord.Net.WebSocket/API/Gateway/ThreadMembersUpdate.cs
+++ b/src/Discord.Net.WebSocket/API/Gateway/ThreadMembersUpdate.cs
@@ -1,9 +1,4 @@
using Newtonsoft.Json;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
namespace Discord.API.Gateway
{
diff --git a/src/Discord.Net.WebSocket/DiscordSocketClient.cs b/src/Discord.Net.WebSocket/DiscordSocketClient.cs
index def163db6..264151e94 100644
--- a/src/Discord.Net.WebSocket/DiscordSocketClient.cs
+++ b/src/Discord.Net.WebSocket/DiscordSocketClient.cs
@@ -434,7 +434,7 @@ namespace Discord.WebSocket
public async Task CreateGlobalApplicationCommandAsync(ApplicationCommandProperties properties, RequestOptions options = null)
{
- var model = await InteractionHelper.CreateGlobalCommand(this, properties, options).ConfigureAwait(false);
+ var model = await InteractionHelper.CreateGlobalCommandAsync(this, properties, options).ConfigureAwait(false);
var entity = State.GetOrAddCommand(model.Id, (id) => SocketApplicationCommand.Create(this, model));
@@ -446,7 +446,7 @@ namespace Discord.WebSocket
public async Task> BulkOverwriteGlobalApplicationCommandsAsync(
ApplicationCommandProperties[] properties, RequestOptions options = null)
{
- var models = await InteractionHelper.BulkOverwriteGlobalCommands(this, properties, options);
+ var models = await InteractionHelper.BulkOverwriteGlobalCommandsAsync(this, properties, options);
var entities = models.Select(x => SocketApplicationCommand.Create(this, x));
diff --git a/src/Discord.Net.WebSocket/Entities/Channels/SocketStageChannel.cs b/src/Discord.Net.WebSocket/Entities/Channels/SocketStageChannel.cs
index a8c0101e7..91bca5054 100644
--- a/src/Discord.Net.WebSocket/Entities/Channels/SocketStageChannel.cs
+++ b/src/Discord.Net.WebSocket/Entities/Channels/SocketStageChannel.cs
@@ -3,7 +3,6 @@ using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
-using System.Text;
using System.Threading.Tasks;
using Model = Discord.API.Channel;
using StageInstance = Discord.API.StageInstance;
@@ -25,7 +24,7 @@ namespace Discord.WebSocket
public bool? IsDiscoverableDisabled { get; private set; }
///
- public bool IsLive { get; private set; } = false;
+ public bool IsLive { get; private set; }
///
/// Returns if the current user is a speaker within the stage, otherwise .
@@ -41,12 +40,8 @@ namespace Discord.WebSocket
internal new SocketStageChannel Clone() => MemberwiseClone() as SocketStageChannel;
-
internal SocketStageChannel(DiscordSocketClient discord, ulong id, SocketGuild guild)
- : base(discord, id, guild)
- {
-
- }
+ : base(discord, id, guild) { }
internal new static SocketStageChannel Create(SocketGuild guild, ClientState state, Model model)
{
@@ -55,11 +50,6 @@ namespace Discord.WebSocket
return entity;
}
- internal override void Update(ClientState state, Model model)
- {
- base.Update(state, model);
- }
-
internal void Update(StageInstance model, bool isLive = false)
{
IsLive = isLive;
@@ -80,11 +70,11 @@ namespace Discord.WebSocket
///
public async Task StartStageAsync(string topic, StagePrivacyLevel privacyLevel = StagePrivacyLevel.GuildOnly, RequestOptions options = null)
{
- var args = new API.Rest.CreateStageInstanceParams()
+ var args = new API.Rest.CreateStageInstanceParams
{
ChannelId = Id,
Topic = topic,
- PrivacyLevel = privacyLevel,
+ PrivacyLevel = privacyLevel
};
var model = await Discord.ApiClient.CreateStageInstanceAsync(args, options).ConfigureAwait(false);
@@ -105,13 +95,13 @@ namespace Discord.WebSocket
{
await Discord.ApiClient.DeleteStageInstanceAsync(Id, options);
- Update(null, false);
+ Update(null);
}
///
public Task RequestToSpeakAsync(RequestOptions options = null)
{
- var args = new API.Rest.ModifyVoiceStateParams()
+ var args = new API.Rest.ModifyVoiceStateParams
{
ChannelId = Id,
RequestToSpeakTimestamp = DateTimeOffset.UtcNow
@@ -122,7 +112,7 @@ namespace Discord.WebSocket
///
public Task BecomeSpeakerAsync(RequestOptions options = null)
{
- var args = new API.Rest.ModifyVoiceStateParams()
+ var args = new API.Rest.ModifyVoiceStateParams
{
ChannelId = Id,
Suppressed = false
@@ -133,7 +123,7 @@ namespace Discord.WebSocket
///
public Task StopSpeakingAsync(RequestOptions options = null)
{
- var args = new API.Rest.ModifyVoiceStateParams()
+ var args = new API.Rest.ModifyVoiceStateParams
{
ChannelId = Id,
Suppressed = true
@@ -144,7 +134,7 @@ namespace Discord.WebSocket
///
public Task MoveToSpeakerAsync(IGuildUser user, RequestOptions options = null)
{
- var args = new API.Rest.ModifyVoiceStateParams()
+ var args = new API.Rest.ModifyVoiceStateParams
{
ChannelId = Id,
Suppressed = false
@@ -156,7 +146,7 @@ namespace Discord.WebSocket
///
public Task RemoveFromSpeakerAsync(IGuildUser user, RequestOptions options = null)
{
- var args = new API.Rest.ModifyVoiceStateParams()
+ var args = new API.Rest.ModifyVoiceStateParams
{
ChannelId = Id,
Suppressed = true
diff --git a/src/Discord.Net.WebSocket/Entities/Channels/SocketThreadChannel.cs b/src/Discord.Net.WebSocket/Entities/Channels/SocketThreadChannel.cs
index 3fd47ec87..7fcafc14a 100644
--- a/src/Discord.Net.WebSocket/Entities/Channels/SocketThreadChannel.cs
+++ b/src/Discord.Net.WebSocket/Entities/Channels/SocketThreadChannel.cs
@@ -5,11 +5,9 @@ using System.Collections.Immutable;
using System.Diagnostics;
using System.IO;
using System.Linq;
-using System.Text;
using System.Threading.Tasks;
using Model = Discord.API.Channel;
using ThreadMember = Discord.API.ThreadMember;
-using MemberUpdates = Discord.API.Gateway.ThreadMembersUpdated;
using System.Collections.Concurrent;
namespace Discord.WebSocket
@@ -72,14 +70,13 @@ namespace Discord.WebSocket
public new IReadOnlyCollection Users =>
_members.Values.ToImmutableArray();
-
- private ConcurrentDictionary _members;
+ private readonly ConcurrentDictionary _members;
private string DebuggerDisplay => $"{Name} ({Id}, Thread)";
- private bool _usersDownloaded = false;
+ private bool _usersDownloaded;
- private object _downloadLock = new object();
+ private readonly object _downloadLock = new object();
internal SocketThreadChannel(DiscordSocketClient discord, SocketGuild guild, ulong id, SocketTextChannel parent)
: base(discord, id, guild)
@@ -103,12 +100,12 @@ namespace Discord.WebSocket
Type = (ThreadType)model.Type;
MessageCount = model.MessageCount.GetValueOrDefault(-1);
MemberCount = model.MemberCount.GetValueOrDefault(-1);
-
+
if (model.ThreadMetadata.IsSpecified)
{
IsArchived = model.ThreadMetadata.Value.Archived;
ArchiveTimestamp = model.ThreadMetadata.Value.ArchiveTimestamp;
- AutoArchiveDuration = (ThreadArchiveDuration)model.ThreadMetadata.Value.AutoArchiveDuration;
+ AutoArchiveDuration = model.ThreadMetadata.Value.AutoArchiveDuration;
IsLocked = model.ThreadMetadata.Value.Locked.GetValueOrDefault(false);
}
@@ -173,12 +170,11 @@ namespace Discord.WebSocket
return Users;
}
-
///
/// Downloads all users that have access to this thread.
///
/// The options to be used when sending the request.
- /// A task representing the asyncronous download operation.
+ /// A task representing the asynchronous download operation.
public async Task DownloadUsersAsync(RequestOptions options = null)
{
var users = await Discord.ApiClient.ListThreadMembersAsync(Id, options);
@@ -193,7 +189,7 @@ namespace Discord.WebSocket
}
}
}
-
+
internal new SocketThreadChannel Clone() => MemberwiseClone() as SocketThreadChannel;
///
@@ -210,7 +206,7 @@ namespace Discord.WebSocket
/// The to add.
/// The options to be used when sending the request.
///
- /// A task that represents the asynchronous operation of adding a member to a thread.
+ /// A task that represents the asynchronous operation of adding a member to a thread.
///
public Task AddUserAsync(IGuildUser user, RequestOptions options = null)
=> Discord.ApiClient.AddThreadMemberAsync(Id, user.Id, options);
@@ -221,60 +217,59 @@ namespace Discord.WebSocket
/// The to remove from this thread.
/// The options to be used when sending the request.
///
- /// A task that represents the asynchronous operation of removing a user from this thread.
+ /// A task that represents the asynchronous operation of removing a user from this thread.
///
public Task RemoveUserAsync(IGuildUser user, RequestOptions options = null)
=> Discord.ApiClient.RemoveThreadMemberAsync(Id, user.Id, options);
-
///
///
/// This method is not supported in threads.
///
public override Task AddPermissionOverwriteAsync(IRole role, OverwritePermissions permissions, RequestOptions options = null)
- => throw new NotImplementedException();
+ => throw new NotSupportedException("This method is not supported in threads.");
///
///
/// This method is not supported in threads.
///
public override Task AddPermissionOverwriteAsync(IUser user, OverwritePermissions permissions, RequestOptions options = null)
- => throw new NotImplementedException();
+ => throw new NotSupportedException("This method is not supported in threads.");
///
///
/// This method is not supported in threads.
///
public override Task CreateInviteAsync(int? maxAge = 86400, int? maxUses = null, bool isTemporary = false, bool isUnique = false, RequestOptions options = null)
- => throw new NotImplementedException();
+ => throw new NotSupportedException("This method is not supported in threads.");
///
///
/// This method is not supported in threads.
///
public override Task CreateInviteToApplicationAsync(ulong applicationId, int? maxAge, int? maxUses = null, bool isTemporary = false, bool isUnique = false, RequestOptions options = null)
- => throw new NotImplementedException();
+ => throw new NotSupportedException("This method is not supported in threads.");
///
///
/// This method is not supported in threads.
///
public override Task CreateInviteToStreamAsync(IUser user, int? maxAge, int? maxUses = null, bool isTemporary = false, bool isUnique = false, RequestOptions options = null)
- => throw new NotImplementedException();
+ => throw new NotSupportedException("This method is not supported in threads.");
///
///
/// This method is not supported in threads.
///
public override Task CreateWebhookAsync(string name, Stream avatar = null, RequestOptions options = null)
- => throw new NotImplementedException();
+ => throw new NotSupportedException("This method is not supported in threads.");
///
///
/// This method is not supported in threads.
///
public override Task> GetInvitesAsync(RequestOptions options = null)
- => throw new NotImplementedException();
+ => throw new NotSupportedException("This method is not supported in threads.");
///
///
@@ -295,14 +290,14 @@ namespace Discord.WebSocket
/// This method is not supported in threads.
///
public override Task GetWebhookAsync(ulong id, RequestOptions options = null)
- => throw new NotImplementedException();
+ => throw new NotSupportedException("This method is not supported in threads.");
///
///
/// This method is not supported in threads.
///
public override Task> GetWebhooksAsync(RequestOptions options = null)
- => throw new NotImplementedException();
+ => throw new NotSupportedException("This method is not supported in threads.");
///
///
@@ -316,28 +311,28 @@ namespace Discord.WebSocket
/// This method is not supported in threads.
///
public override Task RemovePermissionOverwriteAsync(IRole role, RequestOptions options = null)
- => throw new NotImplementedException();
+ => throw new NotSupportedException("This method is not supported in threads.");
///
///
/// This method is not supported in threads.
///
public override Task RemovePermissionOverwriteAsync(IUser user, RequestOptions options = null)
- => throw new NotImplementedException();
+ => throw new NotSupportedException("This method is not supported in threads.");
///
///
/// This method is not supported in threads.
///
public override IReadOnlyCollection PermissionOverwrites
- => throw new NotImplementedException();
+ => throw new NotSupportedException("This method is not supported in threads.");
///
///
/// This method is not supported in threads.
///
public override Task SyncPermissionsAsync(RequestOptions options = null)
- => throw new NotImplementedException();
+ => throw new NotSupportedException("This method is not supported in threads.");
string IChannel.Name => Name;
}
diff --git a/src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs b/src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs
index 4f595539e..5421718cb 100644
--- a/src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs
+++ b/src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs
@@ -906,7 +906,7 @@ namespace Discord.WebSocket
///
public async Task CreateApplicationCommandAsync(ApplicationCommandProperties properties, RequestOptions options = null)
{
- var model = await InteractionHelper.CreateGuildCommand(Discord, Id, properties, options);
+ var model = await InteractionHelper.CreateGuildCommandAsync(Discord, Id, properties, options);
var entity = Discord.State.GetOrAddCommand(model.Id, (id) => SocketApplicationCommand.Create(Discord, model));
@@ -926,7 +926,7 @@ namespace Discord.WebSocket
public async Task> BulkOverwriteApplicationCommandAsync(ApplicationCommandProperties[] properties,
RequestOptions options = null)
{
- var models = await InteractionHelper.BulkOverwriteGuildCommands(Discord, Id, properties, options);
+ var models = await InteractionHelper.BulkOverwriteGuildCommandsAsync(Discord, Id, properties, options);
var entities = models.Select(x => SocketApplicationCommand.Create(Discord, x));
diff --git a/src/Discord.Net.WebSocket/Entities/Interaction/Context Menu Commands/Message Commands/SocketMessageCommand.cs b/src/Discord.Net.WebSocket/Entities/Interaction/Context Menu Commands/Message Commands/SocketMessageCommand.cs
index efd99c2c4..6d0f5ced0 100644
--- a/src/Discord.Net.WebSocket/Entities/Interaction/Context Menu Commands/Message Commands/SocketMessageCommand.cs
+++ b/src/Discord.Net.WebSocket/Entities/Interaction/Context Menu Commands/Message Commands/SocketMessageCommand.cs
@@ -1,7 +1,3 @@
-using Discord.Rest;
-using System;
-using System.Linq;
-using System.Threading.Tasks;
using DataModel = Discord.API.ApplicationCommandInteractionData;
using Model = Discord.API.Interaction;
@@ -20,8 +16,8 @@ namespace Discord.WebSocket
internal SocketMessageCommand(DiscordSocketClient client, Model model, ISocketMessageChannel channel)
: base(client, model, channel)
{
- var dataModel = model.Data.IsSpecified ?
- (DataModel)model.Data.Value
+ var dataModel = model.Data.IsSpecified
+ ? (DataModel)model.Data.Value
: null;
ulong? guildId = null;
@@ -31,7 +27,7 @@ namespace Discord.WebSocket
Data = SocketMessageCommandData.Create(client, dataModel, model.Id, guildId);
}
- new internal static SocketInteraction Create(DiscordSocketClient client, Model model, ISocketMessageChannel channel)
+ internal new static SocketInteraction Create(DiscordSocketClient client, Model model, ISocketMessageChannel channel)
{
var entity = new SocketMessageCommand(client, model, channel);
entity.Update(model);
diff --git a/src/Discord.Net.WebSocket/Entities/Interaction/Context Menu Commands/User Commands/SocketUserCommand.cs b/src/Discord.Net.WebSocket/Entities/Interaction/Context Menu Commands/User Commands/SocketUserCommand.cs
index a61279db9..a4e162039 100644
--- a/src/Discord.Net.WebSocket/Entities/Interaction/Context Menu Commands/User Commands/SocketUserCommand.cs
+++ b/src/Discord.Net.WebSocket/Entities/Interaction/Context Menu Commands/User Commands/SocketUserCommand.cs
@@ -1,7 +1,3 @@
-using Discord.Rest;
-using System;
-using System.Linq;
-using System.Threading.Tasks;
using DataModel = Discord.API.ApplicationCommandInteractionData;
using Model = Discord.API.Interaction;
@@ -20,8 +16,8 @@ namespace Discord.WebSocket
internal SocketUserCommand(DiscordSocketClient client, Model model, ISocketMessageChannel channel)
: base(client, model, channel)
{
- var dataModel = model.Data.IsSpecified ?
- (DataModel)model.Data.Value
+ var dataModel = model.Data.IsSpecified
+ ? (DataModel)model.Data.Value
: null;
ulong? guildId = null;
@@ -31,11 +27,11 @@ namespace Discord.WebSocket
Data = SocketUserCommandData.Create(client, dataModel, model.Id, guildId);
}
- new internal static SocketInteraction Create(DiscordSocketClient client, Model model, ISocketMessageChannel channel)
+ internal new static SocketInteraction Create(DiscordSocketClient client, Model model, ISocketMessageChannel channel)
{
var entity = new SocketUserCommand(client, model, channel);
entity.Update(model);
return entity;
- }
+ }
}
}
diff --git a/src/Discord.Net.WebSocket/Entities/Interaction/Message Components/SocketMessageComponent.cs b/src/Discord.Net.WebSocket/Entities/Interaction/Message Components/SocketMessageComponent.cs
index 2e48b6dd9..624861182 100644
--- a/src/Discord.Net.WebSocket/Entities/Interaction/Message Components/SocketMessageComponent.cs
+++ b/src/Discord.Net.WebSocket/Entities/Interaction/Message Components/SocketMessageComponent.cs
@@ -18,7 +18,7 @@ namespace Discord.WebSocket
///
/// The data received with this interaction, contains the button that was clicked.
///
- new public SocketMessageComponentData Data { get; }
+ public new SocketMessageComponentData Data { get; }
///
/// The message that contained the trigger for this interaction.
@@ -28,20 +28,19 @@ namespace Discord.WebSocket
internal SocketMessageComponent(DiscordSocketClient client, Model model, ISocketMessageChannel channel)
: base(client, model.Id, channel)
{
- var dataModel = model.Data.IsSpecified ?
- (DataModel)model.Data.Value
+ var dataModel = model.Data.IsSpecified
+ ? (DataModel)model.Data.Value
: null;
Data = new SocketMessageComponentData(dataModel);
}
- new internal static SocketMessageComponent Create(DiscordSocketClient client, Model model, ISocketMessageChannel channel)
+ internal new static SocketMessageComponent Create(DiscordSocketClient client, Model model, ISocketMessageChannel channel)
{
var entity = new SocketMessageComponent(client, model, channel);
entity.Update(model);
return entity;
}
-
internal override void Update(Model model)
{
base.Update(model);
@@ -69,7 +68,6 @@ namespace Discord.WebSocket
}
}
}
-
///
public override async Task RespondAsync(
string text = null,
@@ -90,7 +88,7 @@ namespace Discord.WebSocket
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.");
- Preconditions.AtMost(embeds?.Length ?? 0, 10, nameof(embeds), "A max of 10 embeds are allowed.");
+ Preconditions.AtMost(embeds.Length, 10, nameof(embeds), "A max of 10 embeds 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)
@@ -115,7 +113,7 @@ namespace Discord.WebSocket
{
Content = text ?? Optional.Unspecified,
AllowedMentions = allowedMentions?.ToModel(),
- Embeds = embeds?.Select(x => x.ToModel()).ToArray() ?? Optional.Unspecified,
+ Embeds = embeds.Select(x => x.ToModel()).ToArray(),
TTS = isTTS,
Components = component?.Components.Select(x => new API.ActionRowComponent(x)).ToArray() ?? Optional.Unspecified
}
@@ -124,7 +122,7 @@ namespace Discord.WebSocket
if (ephemeral)
response.Data.Value.Flags = MessageFlags.Ephemeral;
- await InteractionHelper.SendInteractionResponse(Discord, response, Id, Token, options);
+ await InteractionHelper.SendInteractionResponseAsync(Discord, response, Id, Token, options);
}
///
@@ -197,13 +195,13 @@ namespace Discord.WebSocket
AllowedMentions = args.AllowedMentions.IsSpecified ? args.AllowedMentions.Value?.ToModel() : Optional.Unspecified,
Embeds = apiEmbeds?.ToArray() ?? Optional.Unspecified,
Components = args.Components.IsSpecified
- ? args.Components.Value?.Components.Select(x => new API.ActionRowComponent(x)).ToArray() ?? new API.ActionRowComponent[0]
+ ? args.Components.Value?.Components.Select(x => new API.ActionRowComponent(x)).ToArray() ?? Array.Empty()
: Optional.Unspecified,
Flags = args.Flags.IsSpecified ? args.Flags.Value ?? Optional.Unspecified : Optional.Unspecified
}
};
- await InteractionHelper.SendInteractionResponse(Discord, response, Id, Token, options);
+ await InteractionHelper.SendInteractionResponseAsync(Discord, response, Id, Token, options);
}
///
@@ -226,15 +224,15 @@ namespace Discord.WebSocket
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.");
- Preconditions.AtMost(embeds?.Length ?? 0, 10, nameof(embeds), "A max of 10 embeds are allowed.");
+ Preconditions.AtMost(embeds.Length, 10, nameof(embeds), "A max of 10 embeds are allowed.");
var args = new API.Rest.CreateWebhookMessageParams
{
Content = text,
AllowedMentions = allowedMentions?.ToModel() ?? Optional.Unspecified,
IsTTS = isTTS,
- Embeds = embeds?.Select(x => x.ToModel()).ToArray() ?? Optional.Unspecified,
- Components = component?.Components.Select(x => new API.ActionRowComponent(x)).ToArray() ?? Optional.Unspecified,
+ Embeds = embeds.Select(x => x.ToModel()).ToArray(),
+ Components = component?.Components.Select(x => new API.ActionRowComponent(x)).ToArray() ?? Optional.Unspecified
};
if (ephemeral)
@@ -265,7 +263,7 @@ namespace Discord.WebSocket
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.");
- Preconditions.AtMost(embeds?.Length ?? 0, 10, nameof(embeds), "A max of 10 embeds are allowed.");
+ Preconditions.AtMost(embeds.Length, 10, nameof(embeds), "A max of 10 embeds are allowed.");
Preconditions.NotNull(fileStream, nameof(fileStream), "File Stream must have data");
Preconditions.NotNullOrWhitespace(fileName, nameof(fileName), "File Name must not be empty or null");
@@ -274,7 +272,7 @@ namespace Discord.WebSocket
Content = text,
AllowedMentions = allowedMentions?.ToModel() ?? Optional.Unspecified,
IsTTS = isTTS,
- Embeds = embeds?.Select(x => x.ToModel()).ToArray() ?? Optional.Unspecified,
+ Embeds = embeds.Select(x => x.ToModel()).ToArray(),
Components = component?.Components.Select(x => new API.ActionRowComponent(x)).ToArray() ?? Optional.Unspecified,
File = fileStream is not null ? new MultipartFile(fileStream, fileName) : Optional.Unspecified
};
@@ -307,7 +305,7 @@ namespace Discord.WebSocket
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.");
- Preconditions.AtMost(embeds?.Length ?? 0, 10, nameof(embeds), "A max of 10 embeds are allowed.");
+ Preconditions.AtMost(embeds.Length, 10, nameof(embeds), "A max of 10 embeds are allowed.");
Preconditions.NotNullOrWhitespace(filePath, nameof(filePath), "Path must exist");
var args = new API.Rest.CreateWebhookMessageParams
@@ -315,7 +313,7 @@ namespace Discord.WebSocket
Content = text,
AllowedMentions = allowedMentions?.ToModel() ?? Optional.Unspecified,
IsTTS = isTTS,
- Embeds = embeds?.Select(x => x.ToModel()).ToArray() ?? Optional.Unspecified,
+ Embeds = embeds.Select(x => x.ToModel()).ToArray(),
Components = component?.Components.Select(x => new API.ActionRowComponent(x)).ToArray() ?? Optional.Unspecified,
File = !string.IsNullOrEmpty(filePath) ? new MultipartFile(new MemoryStream(File.ReadAllBytes(filePath), false), fileName) : Optional.Unspecified
};
@@ -336,11 +334,10 @@ namespace Discord.WebSocket
///
public Task DeferLoadingAsync(bool ephemeral = false, RequestOptions options = null)
{
- var response = new API.InteractionResponse()
+ var response = new API.InteractionResponse
{
Type = InteractionResponseType.DeferredChannelMessageWithSource,
- Data = ephemeral ? new API.InteractionCallbackData() { Flags = MessageFlags.Ephemeral } : Optional.Unspecified
-
+ Data = ephemeral ? new API.InteractionCallbackData { Flags = MessageFlags.Ephemeral } : Optional.Unspecified
};
return Discord.Rest.ApiClient.CreateInteractionResponseAsync(response, Id, Token, options);
@@ -349,11 +346,10 @@ namespace Discord.WebSocket
///
public override Task DeferAsync(bool ephemeral = false, RequestOptions options = null)
{
- var response = new API.InteractionResponse()
+ var response = new API.InteractionResponse
{
Type = InteractionResponseType.DeferredUpdateMessage,
- Data = ephemeral ? new API.InteractionCallbackData() { Flags = MessageFlags.Ephemeral } : Optional.Unspecified
-
+ Data = ephemeral ? new API.InteractionCallbackData { Flags = MessageFlags.Ephemeral } : Optional.Unspecified
};
return Discord.Rest.ApiClient.CreateInteractionResponseAsync(response, Id, Token, options);
diff --git a/src/Discord.Net.WebSocket/Entities/Interaction/Message Components/SocketMessageComponentData.cs b/src/Discord.Net.WebSocket/Entities/Interaction/Message Components/SocketMessageComponentData.cs
index 098478612..408a7f853 100644
--- a/src/Discord.Net.WebSocket/Entities/Interaction/Message Components/SocketMessageComponentData.cs
+++ b/src/Discord.Net.WebSocket/Entities/Interaction/Message Components/SocketMessageComponentData.cs
@@ -1,8 +1,4 @@
-using System;
using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
using Model = Discord.API.MessageComponentInteractionData;
namespace Discord.WebSocket
diff --git a/src/Discord.Net.WebSocket/Entities/Interaction/Slash Commands/SocketAutocompleteInteraction.cs b/src/Discord.Net.WebSocket/Entities/Interaction/Slash Commands/SocketAutocompleteInteraction.cs
index fb6aa2a76..6aa18db23 100644
--- a/src/Discord.Net.WebSocket/Entities/Interaction/Slash Commands/SocketAutocompleteInteraction.cs
+++ b/src/Discord.Net.WebSocket/Entities/Interaction/Slash Commands/SocketAutocompleteInteraction.cs
@@ -2,13 +2,10 @@ using Discord.Rest;
using System;
using System.Collections.Generic;
using System.IO;
-using System.Linq;
-using System.Text;
using System.Threading.Tasks;
using Model = Discord.API.Interaction;
using DataModel = Discord.API.AutocompleteInteractionData;
-
namespace Discord.WebSocket
{
///
@@ -54,7 +51,7 @@ namespace Discord.WebSocket
/// A task that represents the asynchronous operation of responding to this interaction.
///
public Task RespondAsync(IEnumerable result, RequestOptions options = null)
- => InteractionHelper.SendAutocompleteResult(Discord, result, Id, Token, options);
+ => InteractionHelper.SendAutocompleteResultAsync(Discord, result, Id, Token, options);
///
/// Responds to this interaction with a set of choices.
@@ -71,27 +68,31 @@ namespace Discord.WebSocket
/// A task that represents the asynchronous operation of responding to this interaction.
///
public Task RespondAsync(RequestOptions options = null, params AutocompleteResult[] result)
- => InteractionHelper.SendAutocompleteResult(Discord, result, Id, Token, options);
-
+ => InteractionHelper.SendAutocompleteResultAsync(Discord, result, Id, Token, options);
///
[Obsolete("Autocomplete interactions cannot be deferred!", true)]
- public override Task DeferAsync(bool ephemeral = false, RequestOptions options = null) => throw new NotSupportedException();
+ public override Task DeferAsync(bool ephemeral = false, RequestOptions options = null)
+ => throw new NotSupportedException("Autocomplete interactions cannot be deferred!");
///
[Obsolete("Autocomplete interactions cannot have followups!", true)]
- public override Task FollowupAsync(string text = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false, AllowedMentions allowedMentions = null, RequestOptions options = null, MessageComponent component = null, Embed embed = null) => throw new NotSupportedException();
+ public override Task FollowupAsync(string text = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false, AllowedMentions allowedMentions = null, RequestOptions options = null, MessageComponent component = null, Embed embed = null)
+ => throw new NotSupportedException("Autocomplete interactions cannot be deferred!");
///
[Obsolete("Autocomplete interactions cannot have followups!", true)]
- public override Task FollowupWithFileAsync(Stream fileStream, string fileName, string text = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false, AllowedMentions allowedMentions = null, RequestOptions options = null, MessageComponent component = null, Embed embed = null) => throw new NotSupportedException();
+ public override Task FollowupWithFileAsync(Stream fileStream, string fileName, string text = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false, AllowedMentions allowedMentions = null, RequestOptions options = null, MessageComponent component = null, Embed embed = null)
+ => throw new NotSupportedException("Autocomplete interactions cannot be deferred!");
///
[Obsolete("Autocomplete interactions cannot have followups!", true)]
- public override Task FollowupWithFileAsync(string filePath, string text = null, string fileName = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false, AllowedMentions allowedMentions = null, RequestOptions options = null, MessageComponent component = null, Embed embed = null) => throw new NotSupportedException();
+ public override Task FollowupWithFileAsync(string filePath, string text = null, string fileName = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false, AllowedMentions allowedMentions = null, RequestOptions options = null, MessageComponent component = null, Embed embed = null)
+ => throw new NotSupportedException("Autocomplete interactions cannot be deferred!");
///
[Obsolete("Autocomplete interactions cannot have normal responses!", true)]
- public override Task RespondAsync(string text = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false, AllowedMentions allowedMentions = null, RequestOptions options = null, MessageComponent component = null, Embed embed = null) => throw new NotSupportedException();
+ public override Task RespondAsync(string text = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false, AllowedMentions allowedMentions = null, RequestOptions options = null, MessageComponent component = null, Embed embed = null)
+ => throw new NotSupportedException("Autocomplete interactions cannot be deferred!");
}
}
diff --git a/src/Discord.Net.WebSocket/Entities/Interaction/Slash Commands/SocketAutocompleteInteractionData.cs b/src/Discord.Net.WebSocket/Entities/Interaction/Slash Commands/SocketAutocompleteInteractionData.cs
index 1f70cfa4b..d0c44bab1 100644
--- a/src/Discord.Net.WebSocket/Entities/Interaction/Slash Commands/SocketAutocompleteInteractionData.cs
+++ b/src/Discord.Net.WebSocket/Entities/Interaction/Slash Commands/SocketAutocompleteInteractionData.cs
@@ -1,12 +1,8 @@
-using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
using DataModel = Discord.API.AutocompleteInteractionData;
-
namespace Discord.WebSocket
{
///
@@ -46,12 +42,12 @@ namespace Discord.WebSocket
internal SocketAutocompleteInteractionData(DataModel model)
{
- var options = model.Options.SelectMany(x => GetOptions(x));
+ var options = model.Options.SelectMany(GetOptions);
Current = options.FirstOrDefault(x => x.Focused);
Options = options.ToImmutableArray();
- if (options != null && options.Count() == 1 && Current == null)
+ if (Options.Count == 1 && Current == null)
Current = Options.FirstOrDefault();
CommandName = model.Name;
@@ -62,11 +58,11 @@ namespace Discord.WebSocket
private List GetOptions(API.AutocompleteInteractionDataOption model)
{
- List options = new List();
+ var options = new List();
if (model.Options.IsSpecified)
{
- options.AddRange(model.Options.Value.SelectMany(x => GetOptions(x)));
+ options.AddRange(model.Options.Value.SelectMany(GetOptions));
}
else if(model.Focused.IsSpecified)
{
diff --git a/src/Discord.Net.WebSocket/Entities/Interaction/Slash Commands/SocketSlashCommand.cs b/src/Discord.Net.WebSocket/Entities/Interaction/Slash Commands/SocketSlashCommand.cs
index db53f5d08..0594bc09b 100644
--- a/src/Discord.Net.WebSocket/Entities/Interaction/Slash Commands/SocketSlashCommand.cs
+++ b/src/Discord.Net.WebSocket/Entities/Interaction/Slash Commands/SocketSlashCommand.cs
@@ -1,7 +1,3 @@
-using Discord.Rest;
-using System;
-using System.Linq;
-using System.Threading.Tasks;
using DataModel = Discord.API.ApplicationCommandInteractionData;
using Model = Discord.API.Interaction;
@@ -15,13 +11,13 @@ namespace Discord.WebSocket
///
/// The data associated with this interaction.
///
- new public SocketSlashCommandData Data { get; }
+ private new SocketSlashCommandData Data { get; }
internal SocketSlashCommand(DiscordSocketClient client, Model model, ISocketMessageChannel channel)
: base(client, model, channel)
{
- var dataModel = model.Data.IsSpecified ?
- (DataModel)model.Data.Value
+ var dataModel = model.Data.IsSpecified
+ ? (DataModel)model.Data.Value
: null;
ulong? guildId = null;
@@ -31,7 +27,7 @@ namespace Discord.WebSocket
Data = SocketSlashCommandData.Create(client, dataModel, guildId);
}
- new internal static SocketInteraction Create(DiscordSocketClient client, Model model, ISocketMessageChannel channel)
+ internal new static SocketInteraction Create(DiscordSocketClient client, Model model, ISocketMessageChannel channel)
{
var entity = new SocketSlashCommand(client, model, channel);
entity.Update(model);
diff --git a/src/Discord.Net.WebSocket/Entities/Interaction/Slash Commands/SocketSlashCommandData.cs b/src/Discord.Net.WebSocket/Entities/Interaction/Slash Commands/SocketSlashCommandData.cs
index 7b504f119..39dc9a46a 100644
--- a/src/Discord.Net.WebSocket/Entities/Interaction/Slash Commands/SocketSlashCommandData.cs
+++ b/src/Discord.Net.WebSocket/Entities/Interaction/Slash Commands/SocketSlashCommandData.cs
@@ -1,4 +1,3 @@
-using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using Model = Discord.API.ApplicationCommandInteractionData;
@@ -25,7 +24,7 @@ namespace Discord.WebSocket
Options = model.Options.IsSpecified
? model.Options.Value.Select(x => new SocketSlashCommandDataOption(this, x)).ToImmutableArray()
- : null;
+ : ImmutableArray.Create();
}
}
}
diff --git a/src/Discord.Net.WebSocket/Entities/Interaction/Slash Commands/SocketSlashCommandDataOption.cs b/src/Discord.Net.WebSocket/Entities/Interaction/Slash Commands/SocketSlashCommandDataOption.cs
index 6bd1c69e0..265eda75b 100644
--- a/src/Discord.Net.WebSocket/Entities/Interaction/Slash Commands/SocketSlashCommandDataOption.cs
+++ b/src/Discord.Net.WebSocket/Entities/Interaction/Slash Commands/SocketSlashCommandDataOption.cs
@@ -6,7 +6,7 @@ using Model = Discord.API.ApplicationCommandInteractionDataOption;
namespace Discord.WebSocket
{
///
- /// Represents a Websocket-based received by the gateway
+ /// Represents a Websocket-based received by the gateway.
///
public class SocketSlashCommandDataOption : IApplicationCommandInteractionDataOption
{
@@ -61,7 +61,7 @@ namespace Discord.WebSocket
break;
case ApplicationCommandOptionType.Mentionable:
{
- if(data.ResolvableData.GuildMembers.Any(x => x.Key == valueId) || data.ResolvableData.Users.Any(x => x.Key == valueId))
+ if (data.ResolvableData.GuildMembers.Any(x => x.Key == valueId) || data.ResolvableData.Users.Any(x => x.Key == valueId))
{
var guildUser = data.ResolvableData.GuildMembers.FirstOrDefault(x => x.Key == valueId).Value;
@@ -70,7 +70,7 @@ namespace Discord.WebSocket
else
Value = data.ResolvableData.Users.FirstOrDefault(x => x.Key == valueId).Value;
}
- else if(data.ResolvableData.Roles.Any(x => x.Key == valueId))
+ else if (data.ResolvableData.Roles.Any(x => x.Key == valueId))
{
Value = data.ResolvableData.Roles.FirstOrDefault(x => x.Key == valueId).Value;
}
@@ -110,14 +110,13 @@ namespace Discord.WebSocket
}
break;
}
-
}
Options = model.Options.IsSpecified
? model.Options.Value.Select(x => new SocketSlashCommandDataOption(data, x)).ToImmutableArray()
- : null;
+ : ImmutableArray.Create();
}
-#endregion
+ #endregion
#region Converters
public static explicit operator bool(SocketSlashCommandDataOption option)
diff --git a/src/Discord.Net.WebSocket/Entities/Interaction/SocketBaseCommand/SocketApplicationCommand.cs b/src/Discord.Net.WebSocket/Entities/Interaction/SocketBaseCommand/SocketApplicationCommand.cs
index 2eef2e4ce..d986a93f3 100644
--- a/src/Discord.Net.WebSocket/Entities/Interaction/SocketBaseCommand/SocketApplicationCommand.cs
+++ b/src/Discord.Net.WebSocket/Entities/Interaction/SocketBaseCommand/SocketApplicationCommand.cs
@@ -3,7 +3,6 @@ using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
-using System.Text;
using System.Threading.Tasks;
using GatewayModel = Discord.API.Gateway.ApplicationCommandCreatedUpdatedEvent;
using Model = Discord.API.ApplicationCommand;
@@ -11,7 +10,7 @@ using Model = Discord.API.ApplicationCommand;
namespace Discord.WebSocket
{
///
- /// Represends a Websocket-based .
+ /// Represents a Websocket-based .
///
public class SocketApplicationCommand : SocketEntity, IApplicationCommand
{
@@ -85,33 +84,26 @@ namespace Discord.WebSocket
Type = model.Type;
Options = model.Options.IsSpecified
- ? model.Options.Value.Select(x => SocketApplicationCommandOption.Create(x)).ToImmutableArray()
- : new ImmutableArray();
+ ? model.Options.Value.Select(SocketApplicationCommandOption.Create).ToImmutableArray()
+ : ImmutableArray.Create();
}
///
public Task DeleteAsync(RequestOptions options = null)
- => InteractionHelper.DeleteUnknownApplicationCommand(Discord, GuildId, this, options);
+ => InteractionHelper.DeleteUnknownApplicationCommandAsync(Discord, GuildId, this, options);
///
public Task ModifyAsync(Action func, RequestOptions options = null)
{
return ModifyAsync(func, options);
}
-
+
///
public async Task ModifyAsync(Action func, RequestOptions options = null) where TArg : ApplicationCommandProperties
{
- Model command = null;
-
- if (IsGlobalCommand)
- {
- command = await InteractionHelper.ModifyGlobalCommand(Discord, this, func, options).ConfigureAwait(false);
- }
- else
- {
- command = await InteractionHelper.ModifyGuildCommand(Discord, this, GuildId.Value, func, options);
- }
+ var command = IsGlobalCommand
+ ? await InteractionHelper.ModifyGlobalCommandAsync(Discord, this, func, options).ConfigureAwait(false)
+ : await InteractionHelper.ModifyGuildCommandAsync(Discord, this, GuildId.Value, func, options);
Update(command);
}
diff --git a/src/Discord.Net.WebSocket/Entities/Interaction/SocketBaseCommand/SocketApplicationCommandChoice.cs b/src/Discord.Net.WebSocket/Entities/Interaction/SocketBaseCommand/SocketApplicationCommandChoice.cs
index 0f36af0b8..e70efa27b 100644
--- a/src/Discord.Net.WebSocket/Entities/Interaction/SocketBaseCommand/SocketApplicationCommandChoice.cs
+++ b/src/Discord.Net.WebSocket/Entities/Interaction/SocketBaseCommand/SocketApplicationCommandChoice.cs
@@ -1,8 +1,3 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
using Model = Discord.API.ApplicationCommandOptionChoice;
namespace Discord.WebSocket
diff --git a/src/Discord.Net.WebSocket/Entities/Interaction/SocketBaseCommand/SocketApplicationCommandOption.cs b/src/Discord.Net.WebSocket/Entities/Interaction/SocketBaseCommand/SocketApplicationCommandOption.cs
index e4332b02a..8fd5f449c 100644
--- a/src/Discord.Net.WebSocket/Entities/Interaction/SocketBaseCommand/SocketApplicationCommandOption.cs
+++ b/src/Discord.Net.WebSocket/Entities/Interaction/SocketBaseCommand/SocketApplicationCommandOption.cs
@@ -1,9 +1,6 @@
-using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
using Model = Discord.API.ApplicationCommandOption;
namespace Discord.WebSocket
@@ -66,16 +63,16 @@ namespace Discord.WebSocket
: null;
Choices = model.Choices.IsSpecified
- ? model.Choices.Value.Select(x => SocketApplicationCommandChoice.Create(x)).ToImmutableArray()
- : new ImmutableArray();
+ ? model.Choices.Value.Select(SocketApplicationCommandChoice.Create).ToImmutableArray()
+ : ImmutableArray.Create();
Options = model.Options.IsSpecified
- ? model.Options.Value.Select(x => SocketApplicationCommandOption.Create(x)).ToImmutableArray()
- : new ImmutableArray();
+ ? model.Options.Value.Select(Create).ToImmutableArray()
+ : ImmutableArray.Create();
ChannelTypes = model.ChannelTypes.IsSpecified
? model.ChannelTypes.Value.ToImmutableArray()
- : new ImmutableArray();
+ : ImmutableArray.Create();
}
IReadOnlyCollection IApplicationCommandOption.Choices => Choices;
diff --git a/src/Discord.Net.WebSocket/Entities/Interaction/SocketBaseCommand/SocketCommandBase.cs b/src/Discord.Net.WebSocket/Entities/Interaction/SocketBaseCommand/SocketCommandBase.cs
index 8677a4a32..586b785f5 100644
--- a/src/Discord.Net.WebSocket/Entities/Interaction/SocketBaseCommand/SocketCommandBase.cs
+++ b/src/Discord.Net.WebSocket/Entities/Interaction/SocketBaseCommand/SocketCommandBase.cs
@@ -1,10 +1,8 @@
using Discord.Net.Rest;
using Discord.Rest;
using System;
-using System.Collections.Generic;
using System.IO;
using System.Linq;
-using System.Text;
using System.Threading.Tasks;
using DataModel = Discord.API.ApplicationCommandInteractionData;
using Model = Discord.API.Interaction;
@@ -31,13 +29,13 @@ namespace Discord.WebSocket
///
/// The data associated with this interaction.
///
- new internal SocketCommandBaseData Data { get; }
+ internal new SocketCommandBaseData Data { get; }
internal SocketCommandBase(DiscordSocketClient client, Model model, ISocketMessageChannel channel)
: base(client, model.Id, channel)
{
- var dataModel = model.Data.IsSpecified ?
- (DataModel)model.Data.Value
+ var dataModel = model.Data.IsSpecified
+ ? (DataModel)model.Data.Value
: null;
ulong? guildId = null;
@@ -47,7 +45,7 @@ namespace Discord.WebSocket
Data = SocketCommandBaseData.Create(client, dataModel, model.Id, guildId);
}
- new internal static SocketInteraction Create(DiscordSocketClient client, Model model, ISocketMessageChannel channel)
+ internal new static SocketInteraction Create(DiscordSocketClient client, Model model, ISocketMessageChannel channel)
{
var entity = new SocketCommandBase(client, model, channel);
entity.Update(model);
@@ -56,8 +54,8 @@ namespace Discord.WebSocket
internal override void Update(Model model)
{
- var data = model.Data.IsSpecified ?
- (DataModel)model.Data.Value
+ var data = model.Data.IsSpecified
+ ? (DataModel)model.Data.Value
: null;
Data.Update(data);
@@ -85,7 +83,7 @@ namespace Discord.WebSocket
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.");
- Preconditions.AtMost(embeds?.Length ?? 0, 10, nameof(embeds), "A max of 10 embeds are allowed.");
+ Preconditions.AtMost(embeds.Length, 10, nameof(embeds), "A max of 10 embeds 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)
@@ -110,14 +108,14 @@ namespace Discord.WebSocket
{
Content = text,
AllowedMentions = allowedMentions?.ToModel() ?? Optional.Unspecified,
- Embeds = embeds?.Select(x => x.ToModel()).ToArray() ?? Optional.Unspecified,
- TTS = isTTS ? true : Optional.Unspecified,
+ Embeds = embeds.Select(x => x.ToModel()).ToArray(),
+ TTS = isTTS,
Components = component?.Components.Select(x => new API.ActionRowComponent(x)).ToArray() ?? Optional.Unspecified,
Flags = ephemeral ? MessageFlags.Ephemeral : Optional.Unspecified
}
};
- await InteractionHelper.SendInteractionResponse(Discord, response, Id, Token, options);
+ await InteractionHelper.SendInteractionResponseAsync(Discord, response, Id, Token, options);
}
///
@@ -140,14 +138,14 @@ namespace Discord.WebSocket
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.");
- Preconditions.AtMost(embeds?.Length ?? 0, 10, nameof(embeds), "A max of 10 embeds are allowed.");
+ Preconditions.AtMost(embeds.Length, 10, nameof(embeds), "A max of 10 embeds are allowed.");
var args = new API.Rest.CreateWebhookMessageParams
{
Content = text,
AllowedMentions = allowedMentions?.ToModel() ?? Optional.Unspecified,
IsTTS = isTTS,
- Embeds = embeds?.Select(x => x.ToModel()).ToArray() ?? Optional.Unspecified,
+ Embeds = embeds.Select(x => x.ToModel()).ToArray(),
Components = component?.Components.Select(x => new API.ActionRowComponent(x)).ToArray() ?? Optional.Unspecified
};
@@ -179,7 +177,7 @@ namespace Discord.WebSocket
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.");
- Preconditions.AtMost(embeds?.Length ?? 0, 10, nameof(embeds), "A max of 10 embeds are allowed.");
+ Preconditions.AtMost(embeds.Length, 10, nameof(embeds), "A max of 10 embeds are allowed.");
Preconditions.NotNull(fileStream, nameof(fileStream), "File Stream must have data");
Preconditions.NotNullOrEmpty(fileName, nameof(fileName), "File Name must not be empty or null");
@@ -188,7 +186,7 @@ namespace Discord.WebSocket
Content = text,
AllowedMentions = allowedMentions?.ToModel() ?? Optional.Unspecified,
IsTTS = isTTS,
- Embeds = embeds?.Select(x => x.ToModel()).ToArray() ?? Optional.Unspecified,
+ Embeds = embeds.Select(x => x.ToModel()).ToArray(),
Components = component?.Components.Select(x => new API.ActionRowComponent(x)).ToArray() ?? Optional.Unspecified,
File = fileStream is not null ? new MultipartFile(fileStream, fileName) : Optional.Unspecified
};
@@ -221,7 +219,7 @@ namespace Discord.WebSocket
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.");
- Preconditions.AtMost(embeds?.Length ?? 0, 10, nameof(embeds), "A max of 10 embeds are allowed.");
+ Preconditions.AtMost(embeds.Length, 10, nameof(embeds), "A max of 10 embeds are allowed.");
Preconditions.NotNullOrEmpty(filePath, nameof(filePath), "Path must exist");
fileName ??= Path.GetFileName(filePath);
@@ -232,7 +230,7 @@ namespace Discord.WebSocket
Content = text,
AllowedMentions = allowedMentions?.ToModel() ?? Optional.Unspecified,
IsTTS = isTTS,
- Embeds = embeds?.Select(x => x.ToModel()).ToArray() ?? Optional.Unspecified,
+ Embeds = embeds.Select(x => x.ToModel()).ToArray(),
Components = component?.Components.Select(x => new API.ActionRowComponent(x)).ToArray() ?? Optional.Unspecified,
File = !string.IsNullOrEmpty(filePath) ? new MultipartFile(new MemoryStream(File.ReadAllBytes(filePath), false), fileName) : Optional.Unspecified
};
diff --git a/src/Discord.Net.WebSocket/Entities/Interaction/SocketBaseCommand/SocketCommandBaseData.cs b/src/Discord.Net.WebSocket/Entities/Interaction/SocketBaseCommand/SocketCommandBaseData.cs
index cac1ce2df..cb2f01f5f 100644
--- a/src/Discord.Net.WebSocket/Entities/Interaction/SocketBaseCommand/SocketCommandBaseData.cs
+++ b/src/Discord.Net.WebSocket/Entities/Interaction/SocketBaseCommand/SocketCommandBaseData.cs
@@ -1,6 +1,4 @@
using System.Collections.Generic;
-using System.Collections.Immutable;
-using System.Linq;
using Model = Discord.API.ApplicationCommandInteractionData;
namespace Discord.WebSocket
diff --git a/src/Discord.Net.WebSocket/Entities/Interaction/SocketBaseCommand/SocketResolvableData.cs b/src/Discord.Net.WebSocket/Entities/Interaction/SocketBaseCommand/SocketResolvableData.cs
index c76bc49c3..c065637ca 100644
--- a/src/Discord.Net.WebSocket/Entities/Interaction/SocketBaseCommand/SocketResolvableData.cs
+++ b/src/Discord.Net.WebSocket/Entities/Interaction/SocketBaseCommand/SocketResolvableData.cs
@@ -1,8 +1,4 @@
-using System;
using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
namespace Discord.WebSocket
{
diff --git a/src/Discord.Net.WebSocket/Entities/Interaction/SocketInteraction.cs b/src/Discord.Net.WebSocket/Entities/Interaction/SocketInteraction.cs
index 47b0ebcb6..2863e772d 100644
--- a/src/Discord.Net.WebSocket/Entities/Interaction/SocketInteraction.cs
+++ b/src/Discord.Net.WebSocket/Entities/Interaction/SocketInteraction.cs
@@ -63,9 +63,9 @@ namespace Discord.WebSocket
{
if (model.Type == InteractionType.ApplicationCommand)
{
- var dataModel = model.Data.IsSpecified ?
- (DataModel)model.Data.Value
- : null;
+ var dataModel = model.Data.IsSpecified
+ ? (DataModel)model.Data.Value
+ : null;
if (dataModel == null)
return null;
@@ -75,15 +75,17 @@ namespace Discord.WebSocket
ApplicationCommandType.Slash => SocketSlashCommand.Create(client, model, channel),
ApplicationCommandType.Message => SocketMessageCommand.Create(client, model, channel),
ApplicationCommandType.User => SocketUserCommand.Create(client, model, channel),
- _ => null,
+ _ => null
};
}
- else if (model.Type == InteractionType.MessageComponent)
+
+ if (model.Type == InteractionType.MessageComponent)
return SocketMessageComponent.Create(client, model, channel);
- else if (model.Type == InteractionType.ApplicationCommandAutocomplete)
+
+ if (model.Type == InteractionType.ApplicationCommandAutocomplete)
return SocketAutocompleteInteraction.Create(client, model, channel);
- else
- return null;
+
+ return null;
}
internal virtual void Update(Model model)
@@ -138,7 +140,7 @@ namespace Discord.WebSocket
///
/// The sent message.
///
- public abstract Task FollowupAsync(string text = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false,
+ public abstract Task FollowupAsync(string text = null, Embed[] embeds = null, bool isTTS = false, bool ephemeral = false,
AllowedMentions allowedMentions = null, RequestOptions options = null, MessageComponent component = null, Embed embed = null);
///
@@ -195,7 +197,7 @@ namespace Discord.WebSocket
/// A that represents the initial response.
public async Task ModifyOriginalResponseAsync(Action func, RequestOptions options = null)
{
- var model = await InteractionHelper.ModifyInteractionResponse(Discord, Token, func, options);
+ var model = await InteractionHelper.ModifyInteractionResponseAsync(Discord, Token, func, options);
return RestInteractionMessage.Create(Discord, model, Token, Channel);
}
@@ -214,20 +216,20 @@ namespace Discord.WebSocket
// Tokens last for 15 minutes according to https://discord.com/developers/docs/interactions/slash-commands#responding-to-an-interaction
return (DateTime.UtcNow - CreatedAt.UtcDateTime).TotalMinutes <= 15d;
}
-#endregion
+ #endregion
#region IDiscordInteraction
///
- async Task IDiscordInteraction.FollowupAsync (string text, Embed[] embeds, bool isTTS, bool ephemeral, AllowedMentions allowedMentions,
+ async Task IDiscordInteraction.FollowupAsync(string text, Embed[] embeds, bool isTTS, bool ephemeral, AllowedMentions allowedMentions,
RequestOptions options, MessageComponent component, Embed embed)
=> await FollowupAsync(text, embeds, isTTS, ephemeral, allowedMentions, options, component, embed).ConfigureAwait(false);
///
- async Task IDiscordInteraction.GetOriginalResponseAsync (RequestOptions options)
+ async Task IDiscordInteraction.GetOriginalResponseAsync(RequestOptions options)
=> await GetOriginalResponseAsync(options).ConfigureAwait(false);
///
- async Task IDiscordInteraction.ModifyOriginalResponseAsync (Action