diff --git a/src/Discord.Net.Core/Discord.Net.Core.csproj b/src/Discord.Net.Core/Discord.Net.Core.csproj
index f62f61e26..9bebe08ae 100644
--- a/src/Discord.Net.Core/Discord.Net.Core.csproj
+++ b/src/Discord.Net.Core/Discord.Net.Core.csproj
@@ -8,7 +8,7 @@
net461;netstandard2.0;netstandard2.1
netstandard2.0;netstandard2.1
Discord.Net.Labs.Core
- 2.3.8
+ 2.3.9-pre
Discord.Net.Labs.Core
https://github.com/Discord-Net-Labs/Discord.Net-Labs
Temporary.png
diff --git a/src/Discord.Net.Core/Discord.Net.Core.xml b/src/Discord.Net.Core/Discord.Net.Core.xml
index 5baa090bf..f60639030 100644
--- a/src/Discord.Net.Core/Discord.Net.Core.xml
+++ b/src/Discord.Net.Core/Discord.Net.Core.xml
@@ -3932,6 +3932,11 @@
A .
+
+
+
+
+
Provides properties that are used to modify a with the specified changes.
@@ -4032,6 +4037,11 @@
+
+
+ The type of this data's option.
+
+
Present if this option is a group or subcommand.
diff --git a/src/Discord.Net.Core/Entities/Interactions/ApplicationCommandOptionType.cs b/src/Discord.Net.Core/Entities/Interactions/ApplicationCommandOptionType.cs
index 97ab54d3d..bf7633660 100644
--- a/src/Discord.Net.Core/Entities/Interactions/ApplicationCommandOptionType.cs
+++ b/src/Discord.Net.Core/Entities/Interactions/ApplicationCommandOptionType.cs
@@ -49,6 +49,11 @@ namespace Discord
///
/// A .
///
- Role = 8
+ Role = 8,
+
+ ///
+ ///
+ ///
+ Mentionable = 9
}
}
diff --git a/src/Discord.Net.Core/Entities/Interactions/IApplicationCommandInteractionDataOption.cs b/src/Discord.Net.Core/Entities/Interactions/IApplicationCommandInteractionDataOption.cs
index ffc94c428..999309979 100644
--- a/src/Discord.Net.Core/Entities/Interactions/IApplicationCommandInteractionDataOption.cs
+++ b/src/Discord.Net.Core/Entities/Interactions/IApplicationCommandInteractionDataOption.cs
@@ -24,6 +24,11 @@ namespace Discord
///
object Value { get; }
+ ///
+ /// The type of this data's option.
+ ///
+ ApplicationCommandOptionType Type { get; }
+
///
/// Present if this option is a group or subcommand.
///
diff --git a/src/Discord.Net.Core/Entities/Interactions/SlashCommandBuilder.cs b/src/Discord.Net.Core/Entities/Interactions/SlashCommandBuilder.cs
index c3c1aaa7f..8011f9c8e 100644
--- a/src/Discord.Net.Core/Entities/Interactions/SlashCommandBuilder.cs
+++ b/src/Discord.Net.Core/Entities/Interactions/SlashCommandBuilder.cs
@@ -341,7 +341,7 @@ namespace Discord
Default = this.Default,
Required = this.Required,
Type = this.Type,
- Options = new List(this.Options.Select(x => x.Build())),
+ Options = this.Options?.Count > 0 ? new List(this.Options.Select(x => x.Build())) : null,
Choices = this.Choices
};
}
diff --git a/src/Discord.Net.Rest/API/Common/ApplicationCommandInteractionData.cs b/src/Discord.Net.Rest/API/Common/ApplicationCommandInteractionData.cs
index 118dcc0f0..c72e8a686 100644
--- a/src/Discord.Net.Rest/API/Common/ApplicationCommandInteractionData.cs
+++ b/src/Discord.Net.Rest/API/Common/ApplicationCommandInteractionData.cs
@@ -12,6 +12,10 @@ namespace Discord.API
public string Name { get; set; }
[JsonProperty("options")]
- public List Options { get; set; } = new();
+ public List Options { get; set; }
+
+ [JsonProperty("resolved")]
+ public Optional Resolved { get; set; }
+
}
}
diff --git a/src/Discord.Net.Rest/API/Common/ApplicationCommandInteractionDataResolved.cs b/src/Discord.Net.Rest/API/Common/ApplicationCommandInteractionDataResolved.cs
index fe44fbc79..46eca6b71 100644
--- a/src/Discord.Net.Rest/API/Common/ApplicationCommandInteractionDataResolved.cs
+++ b/src/Discord.Net.Rest/API/Common/ApplicationCommandInteractionDataResolved.cs
@@ -6,15 +6,15 @@ namespace Discord.API
internal class ApplicationCommandInteractionDataResolved
{
[JsonProperty("users")]
- public Optional> Users { get; set; }
+ public Optional> Users { get; set; }
[JsonProperty("members")]
- public Optional> Members { get; set; }
+ public Optional> Members { get; set; }
[JsonProperty("channels")]
- public Optional> Channels { get; set; }
+ public Optional> Channels { get; set; }
[JsonProperty("roles")]
- public Optional> Roles { get; set; }
+ public Optional> Roles { get; set; }
}
}
diff --git a/src/Discord.Net.Rest/Discord.Net.Rest.csproj b/src/Discord.Net.Rest/Discord.Net.Rest.csproj
index dde0765d8..ed8dbb66e 100644
--- a/src/Discord.Net.Rest/Discord.Net.Rest.csproj
+++ b/src/Discord.Net.Rest/Discord.Net.Rest.csproj
@@ -9,7 +9,7 @@
netstandard2.0;netstandard2.1
Temporary.png
https://github.com/Discord-Net-Labs/Discord.Net-Labs
- 2.3.8
+ 2.3.9-pre
Discord.Net.Labs.Rest
https://github.com/Discord-Net-Labs/Discord.Net-Labs
2.3.4
diff --git a/src/Discord.Net.Rest/Entities/Interactions/InteractionHelper.cs b/src/Discord.Net.Rest/Entities/Interactions/InteractionHelper.cs
index c5a8347c7..a02bf9045 100644
--- a/src/Discord.Net.Rest/Entities/Interactions/InteractionHelper.cs
+++ b/src/Discord.Net.Rest/Entities/Interactions/InteractionHelper.cs
@@ -10,20 +10,20 @@ namespace Discord.Rest
{
internal static class InteractionHelper
{
- internal static async Task SendInteractionResponse(BaseDiscordClient client, IMessageChannel channel, InteractionResponse response,
+ internal static Task SendInteractionResponse(BaseDiscordClient client, IMessageChannel channel, InteractionResponse response,
ulong interactionId, string interactionToken, RequestOptions options = null)
{
- await client.ApiClient.CreateInteractionResponse(response, interactionId, interactionToken, options).ConfigureAwait(false);
-
- // get the original message
- var msg = await client.ApiClient.GetInteractionResponse(interactionToken).ConfigureAwait(false);
-
- var entity = RestInteractionMessage.Create(client, msg, interactionToken, channel);
+ return client.ApiClient.CreateInteractionResponse(response, interactionId, interactionToken, options);
+ }
- return entity;
+ internal static async Task GetOriginalResponseAsync(BaseDiscordClient client, IMessageChannel channel,
+ IDiscordInteraction interaction, RequestOptions options = null)
+ {
+ var model = await client.ApiClient.GetInteractionResponse(interaction.Token, options).ConfigureAwait(false);
+ return RestInteractionMessage.Create(client, model, interaction.Token, channel);
}
- internal static async Task SendFollowupAsync(BaseDiscordClient client, API.Rest.CreateWebhookMessageParams args,
+ internal static async Task SendFollowupAsync(BaseDiscordClient client, CreateWebhookMessageParams args,
string token, IMessageChannel channel, RequestOptions options = null)
{
var model = await client.ApiClient.CreateInteractionFollowupMessage(args, token, options).ConfigureAwait(false);
diff --git a/src/Discord.Net.WebSocket/Discord.Net.WebSocket.csproj b/src/Discord.Net.WebSocket/Discord.Net.WebSocket.csproj
index 315767583..6660f1311 100644
--- a/src/Discord.Net.WebSocket/Discord.Net.WebSocket.csproj
+++ b/src/Discord.Net.WebSocket/Discord.Net.WebSocket.csproj
@@ -8,7 +8,7 @@
net461;netstandard2.0;netstandard2.1
netstandard2.0;netstandard2.1
true
- 2.3.8
+ 2.3.9-pre
https://github.com/Discord-Net-Labs/Discord.Net-Labs
https://github.com/Discord-Net-Labs/Discord.Net-Labs
Temporary.png
diff --git a/src/Discord.Net.WebSocket/Discord.Net.WebSocket.xml b/src/Discord.Net.WebSocket/Discord.Net.WebSocket.xml
index 30689f61f..e08511d5d 100644
--- a/src/Discord.Net.WebSocket/Discord.Net.WebSocket.xml
+++ b/src/Discord.Net.WebSocket/Discord.Net.WebSocket.xml
@@ -3299,41 +3299,17 @@
The data associated with this interaction.
-
+
- Responds to an Interaction.
-
- If you have set to , You should use
- instead.
-
+ Gets the original response to this slash command.
- The text of the message to be sent.
- if the message should be read out by a text-to-speech reader, otherwise .
- A to send with this response.
- The type of response to this Interaction.
- if the response should be hidden to everyone besides the invoker of the command, otherwise .
- The allowed mentions for this response.
- The request options for this response.
-
- The sent as the response. If this is the first acknowledgement, it will return null.
-
- Message content is too long, length must be less or equal to .
- The parameters provided were invalid or the token was invalid.
+ A that represents the initial response to this interaction.
+
+
+
-
- Sends a followup message for this interaction.
-
- The text of the message to be sent
- if the message should be read out by a text-to-speech reader, otherwise .
- A to send with this response.
- The type of response to this Interaction.
- /// if the response should be hidden to everyone besides the invoker of the command, otherwise .
- The allowed mentions for this response.
- The request options for this response.
-
- The sent message.
-
+
@@ -3359,6 +3335,9 @@
+
+
+
The sub command options received for this sub command group.
@@ -3420,9 +3399,6 @@
The allowed mentions for this response.
The request options for this response.
A to be sent with this response
-
- The sent as the response. If this is the first acknowledgement, it will return null.
-
Message content is too long, length must be less or equal to .
The parameters provided were invalid or the token was invalid.
@@ -3442,6 +3418,13 @@
The sent message.
+
+
+ Gets the original response for this interaction.
+
+ The request options for this async request.
+ A that represents the intitial response, or if there is no response.
+
Acknowledges this interaction with the .
diff --git a/src/Discord.Net.WebSocket/DiscordSocketClient.cs b/src/Discord.Net.WebSocket/DiscordSocketClient.cs
index 3ea599545..4fe1cfdfe 100644
--- a/src/Discord.Net.WebSocket/DiscordSocketClient.cs
+++ b/src/Discord.Net.WebSocket/DiscordSocketClient.cs
@@ -25,7 +25,7 @@ namespace Discord.WebSocket
public partial class DiscordSocketClient : BaseSocketClient, IDiscordClient
{
private readonly ConcurrentQueue _largeGuilds;
- private readonly JsonSerializer _serializer;
+ internal readonly JsonSerializer _serializer;
private readonly DiscordShardedClient _shardedClient;
private readonly DiscordSocketClient _parentClient;
private readonly ConcurrentQueue _heartbeatTimes;
diff --git a/src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs b/src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs
index bd2945a71..b4f6bd086 100644
--- a/src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs
+++ b/src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs
@@ -794,6 +794,16 @@ namespace Discord.WebSocket
return null;
}
+ internal SocketRole AddOrUpdateRole(RoleModel model)
+ {
+ if (_roles.TryGetValue(model.Id, out SocketRole role))
+ _roles[model.Id].Update(this.Discord.State, model);
+ else
+ role = AddRole(model);
+
+ return role;
+ }
+
//Users
///
public Task AddGuildUserAsync(ulong id, string accessToken, Action func = null, RequestOptions options = null)
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 9f9f5c960..beda6eb53 100644
--- a/src/Discord.Net.WebSocket/Entities/Interaction/Message Components/SocketMessageComponent.cs
+++ b/src/Discord.Net.WebSocket/Entities/Interaction/Message Components/SocketMessageComponent.cs
@@ -92,7 +92,7 @@ namespace Discord.WebSocket
///
/// Message content is too long, length must be less or equal to .
/// The parameters provided were invalid or the token was invalid.
- public override async Task RespondAsync(string text = null, bool isTTS = false, Embed embed = null, InteractionResponseType type = InteractionResponseType.ChannelMessageWithSource,
+ public override async Task RespondAsync(string text = null, bool isTTS = false, Embed embed = null, InteractionResponseType type = InteractionResponseType.ChannelMessageWithSource,
bool ephemeral = false, AllowedMentions allowedMentions = null, RequestOptions options = null, MessageComponent component = null)
{
if (type == InteractionResponseType.Pong)
@@ -102,7 +102,10 @@ namespace Discord.WebSocket
throw new InvalidOperationException("Interaction token is no longer valid");
if (Discord.AlwaysAcknowledgeInteractions)
- return await FollowupAsync(text, isTTS, embed, ephemeral, type, allowedMentions, options);
+ {
+ await FollowupAsync(text, isTTS, embed, ephemeral, type, allowedMentions, options);
+ return;
+ }
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.");
@@ -141,7 +144,7 @@ namespace Discord.WebSocket
if (ephemeral)
response.Data.Value.Flags = 64;
- return await InteractionHelper.SendInteractionResponse(this.Discord, this.Channel, response, this.Id, Token, options);
+ await InteractionHelper.SendInteractionResponse(this.Discord, this.Channel, response, this.Id, Token, options);
}
///
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 faf50e38e..1b94f5c83 100644
--- a/src/Discord.Net.WebSocket/Entities/Interaction/Slash Commands/SocketSlashCommand.cs
+++ b/src/Discord.Net.WebSocket/Entities/Interaction/Slash Commands/SocketSlashCommand.cs
@@ -22,10 +22,14 @@ namespace Discord.WebSocket
: base(client, model.Id, channel)
{
var dataModel = model.Data.IsSpecified ?
- (model.Data.Value as JToken).ToObject()
+ (model.Data.Value as JToken).ToObject(client._serializer)
: null;
- Data = SocketSlashCommandData.Create(client, dataModel, model.Id);
+ ulong? guildId = null;
+ if (this.Channel is SocketGuildChannel guildChannel)
+ guildId = guildChannel.Guild.Id;
+
+ Data = SocketSlashCommandData.Create(client, dataModel, model.Id, guildId);
}
new internal static SocketInteraction Create(DiscordSocketClient client, Model model, ISocketMessageChannel channel)
@@ -38,7 +42,7 @@ namespace Discord.WebSocket
internal override void Update(Model model)
{
var data = model.Data.IsSpecified ?
- (model.Data.Value as JToken).ToObject()
+ (model.Data.Value as JToken).ToObject(Discord._serializer)
: null;
this.Data.Update(data);
@@ -47,26 +51,21 @@ namespace Discord.WebSocket
}
///
- /// Responds to an Interaction.
- ///
- /// If you have set to , You should use
- /// instead.
- ///
+ /// Gets the original response to this slash command.
///
- /// The text of the message to be sent.
- /// if the message should be read out by a text-to-speech reader, otherwise .
- /// A to send with this response.
- /// The type of response to this Interaction.
- /// if the response should be hidden to everyone besides the invoker of the command, otherwise .
- /// The allowed mentions for this response.
- /// The request options for this response.
- ///
- /// The sent as the response. If this is the first acknowledgement, it will return null.
- ///
- /// Message content is too long, length must be less or equal to .
- /// The parameters provided were invalid or the token was invalid.
-
- public override async Task RespondAsync(string text = null, bool isTTS = false, Embed embed = null, InteractionResponseType type = InteractionResponseType.ChannelMessageWithSource,
+ /// A that represents the initial response to this interaction.
+ public async Task GetOriginalResponse()
+ {
+ // get the original message
+ var msg = await Discord.ApiClient.GetInteractionResponse(this.Token).ConfigureAwait(false);
+
+ var entity = RestInteractionMessage.Create(Discord, msg, this.Token, this.Channel);
+
+ return entity;
+ }
+
+ ///
+ public override async Task RespondAsync(string text = null, bool isTTS = false, Embed embed = null, InteractionResponseType type = InteractionResponseType.ChannelMessageWithSource,
bool ephemeral = false, AllowedMentions allowedMentions = null, RequestOptions options = null, MessageComponent component = null)
{
if (type == InteractionResponseType.Pong)
@@ -79,7 +78,10 @@ namespace Discord.WebSocket
throw new InvalidOperationException("Interaction token is no longer valid");
if (Discord.AlwaysAcknowledgeInteractions)
- return await FollowupAsync(text, isTTS, embed, ephemeral, type, allowedMentions, options); // The arguments should be passed? What was i thinking...
+ {
+ await FollowupAsync(text, isTTS, embed, ephemeral, type, allowedMentions, options);
+ return;
+ }
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.");
@@ -118,22 +120,10 @@ namespace Discord.WebSocket
if (ephemeral)
response.Data.Value.Flags = 64;
- return await InteractionHelper.SendInteractionResponse(this.Discord, this.Channel, response, this.Id, Token, options);
+ await InteractionHelper.SendInteractionResponse(this.Discord, this.Channel, response, this.Id, Token, options);
}
- ///
- /// Sends a followup message for this interaction.
- ///
- /// The text of the message to be sent
- /// if the message should be read out by a text-to-speech reader, otherwise .
- /// A to send with this response.
- /// The type of response to this Interaction.
- /// /// if the response should be hidden to everyone besides the invoker of the command, otherwise .
- /// The allowed mentions for this response.
- /// The request options for this response.
- ///
- /// The sent message.
- ///
+ ///
public override async Task FollowupAsync(string text = null, bool isTTS = false, Embed embed = null, bool ephemeral = false,
InteractionResponseType type = InteractionResponseType.ChannelMessageWithSource,
AllowedMentions allowedMentions = null, RequestOptions options = null, MessageComponent component = null)
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 b3cb5ddd2..95157de89 100644
--- a/src/Discord.Net.WebSocket/Entities/Interaction/Slash Commands/SocketSlashCommandData.cs
+++ b/src/Discord.Net.WebSocket/Entities/Interaction/Slash Commands/SocketSlashCommandData.cs
@@ -18,15 +18,71 @@ namespace Discord.WebSocket
///
public IReadOnlyCollection Options { get; private set; }
- internal SocketSlashCommandData(DiscordSocketClient client, ulong id)
- : base(client, id)
+ internal Dictionary guildMembers { get; private set; } = new();
+ internal Dictionary users { get; private set; } = new();
+ internal Dictionary channels { get; private set; } = new();
+ internal Dictionary roles { get; private set; } = new();
+
+ private ulong? guildId;
+
+ internal SocketSlashCommandData(DiscordSocketClient client, Model model, ulong? guildId)
+ : base(client, model.Id)
{
+ this.guildId = guildId;
+
+ if (model.Resolved.IsSpecified)
+ {
+ var guild = this.guildId.HasValue ? Discord.GetGuild(this.guildId.Value) : null;
+
+ var resolved = model.Resolved.Value;
+
+ if (resolved.Users.IsSpecified)
+ {
+ foreach (var user in resolved.Users.Value)
+ {
+ var socketUser = Discord.GetOrCreateUser(this.Discord.State, user.Value);
+
+ this.users.Add(ulong.Parse(user.Key), socketUser);
+ }
+ }
+
+ if (resolved.Channels.IsSpecified)
+ {
+ foreach (var channel in resolved.Channels.Value)
+ {
+ SocketChannel socketChannel = channel.Value.GuildId.IsSpecified
+ ? SocketGuildChannel.Create(Discord.GetGuild(channel.Value.GuildId.Value), Discord.State, channel.Value)
+ : SocketDMChannel.Create(Discord, Discord.State, channel.Value);
+
+ Discord.State.AddChannel(socketChannel);
+ this.channels.Add(ulong.Parse(channel.Key), socketChannel);
+ }
+ }
+
+ if (resolved.Members.IsSpecified)
+ {
+ foreach (var member in resolved.Members.Value)
+ {
+ member.Value.User = resolved.Users.Value[member.Key];
+ var user = guild.AddOrUpdateUser(member.Value);
+ this.guildMembers.Add(ulong.Parse(member.Key), user);
+ }
+ }
+ if (resolved.Roles.IsSpecified)
+ {
+ foreach (var role in resolved.Roles.Value)
+ {
+ var socketRole = guild.AddOrUpdateRole(role.Value);
+ this.roles.Add(ulong.Parse(role.Key), socketRole);
+ }
+ }
+ }
}
- internal static SocketSlashCommandData Create(DiscordSocketClient client, Model model, ulong id)
+ internal static SocketSlashCommandData Create(DiscordSocketClient client, Model model, ulong id, ulong? guildId)
{
- var entity = new SocketSlashCommandData(client, model.Id);
+ var entity = new SocketSlashCommandData(client, model, guildId);
entity.Update(model);
return entity;
}
@@ -35,7 +91,7 @@ namespace Discord.WebSocket
this.Name = model.Name;
this.Options = model.Options.Any()
- ? model.Options.Select(x => new SocketSlashCommandDataOption(x, this.Discord)).ToImmutableArray()
+ ? model.Options.Select(x => new SocketSlashCommandDataOption(this, x)).ToImmutableArray()
: null;
}
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 e7ff1c5d5..c9e29599c 100644
--- a/src/Discord.Net.WebSocket/Entities/Interaction/Slash Commands/SocketSlashCommandDataOption.cs
+++ b/src/Discord.Net.WebSocket/Entities/Interaction/Slash Commands/SocketSlashCommandDataOption.cs
@@ -16,22 +16,25 @@ namespace Discord.WebSocket
///
public object Value { get; private set; }
+ ///
+ public ApplicationCommandOptionType Type { get; private set; }
+
///
/// The sub command options received for this sub command group.
///
public IReadOnlyCollection Options { get; private set; }
- private DiscordSocketClient discord;
+
+ private SocketSlashCommandData data;
internal SocketSlashCommandDataOption() { }
- internal SocketSlashCommandDataOption(Model model, DiscordSocketClient discord)
+ internal SocketSlashCommandDataOption(SocketSlashCommandData data, Model model)
{
this.Name = model.Name;
this.Value = model.Value.IsSpecified ? model.Value.Value : null;
- this.discord = discord;
this.Options = model.Options.Any()
- ? model.Options.Select(x => new SocketSlashCommandDataOption(x, discord)).ToImmutableArray()
+ ? model.Options.Select(x => new SocketSlashCommandDataOption(data, x)).ToImmutableArray()
: null;
}
@@ -43,16 +46,12 @@ namespace Discord.WebSocket
public static explicit operator string(SocketSlashCommandDataOption option)
=> option.Value.ToString();
- public static explicit operator SocketGuildChannel(SocketSlashCommandDataOption option)
+ public static explicit operator SocketChannel(SocketSlashCommandDataOption option)
{
- if (option.Value is ulong id)
+ if(ulong.TryParse(option.Value.ToString(), out ulong id))
{
- var guild = option.discord.GetGuild(id);
-
- if (guild == null)
- return null;
-
- return guild.GetChannel(id);
+ if (option.data.channels.TryGetValue(id, out var channel))
+ return channel;
}
return null;
@@ -60,34 +59,35 @@ namespace Discord.WebSocket
public static explicit operator SocketRole(SocketSlashCommandDataOption option)
{
- if (option.Value is ulong id)
+ if (ulong.TryParse(option.Value.ToString(), out ulong id))
{
- var guild = option.discord.GetGuild(id);
-
- if (guild == null)
- return null;
-
- return guild.GetRole(id);
+ if (option.data.roles.TryGetValue(id, out var role))
+ return role;
}
return null;
}
- public static explicit operator SocketGuildUser(SocketSlashCommandDataOption option)
+ public static explicit operator SocketUser(SocketSlashCommandDataOption option)
{
- if(option.Value is ulong id)
+ if (ulong.TryParse(option.Value.ToString(), out ulong id))
{
- var guild = option.discord.GetGuild(id);
+ if (option.data.users.TryGetValue(id, out var user))
+ return user;
+ }
- if (guild == null)
- return null;
+ return null;
+ }
- return guild.GetUser(id);
- }
+ public static explicit operator SocketGuildUser(SocketSlashCommandDataOption option)
+ {
+ if (option.Value as SocketUser is SocketGuildUser guildUser)
+ return guildUser;
return null;
}
+
IReadOnlyCollection IApplicationCommandInteractionDataOption.Options => this.Options;
}
}
diff --git a/src/Discord.Net.WebSocket/Entities/Interaction/SocketInteraction.cs b/src/Discord.Net.WebSocket/Entities/Interaction/SocketInteraction.cs
index 4b213f4ec..a31ecc692 100644
--- a/src/Discord.Net.WebSocket/Entities/Interaction/SocketInteraction.cs
+++ b/src/Discord.Net.WebSocket/Entities/Interaction/SocketInteraction.cs
@@ -110,13 +110,10 @@ namespace Discord.WebSocket
/// The allowed mentions for this response.
/// The request options for this response.
/// A to be sent with this response
- ///
- /// The sent as the response. If this is the first acknowledgement, it will return null.
- ///
/// Message content is too long, length must be less or equal to .
/// The parameters provided were invalid or the token was invalid.
- public abstract Task RespondAsync(string text = null, bool isTTS = false, Embed embed = null, InteractionResponseType type = InteractionResponseType.ChannelMessageWithSource,
+ public abstract Task RespondAsync(string text = null, bool isTTS = false, Embed embed = null, InteractionResponseType type = InteractionResponseType.ChannelMessageWithSource,
bool ephemeral = false, AllowedMentions allowedMentions = null, RequestOptions options = null, MessageComponent component = null);
///
@@ -137,6 +134,16 @@ namespace Discord.WebSocket
InteractionResponseType type = InteractionResponseType.ChannelMessageWithSource,
AllowedMentions allowedMentions = null, RequestOptions options = null, MessageComponent component = null);
+ ///
+ /// Gets the original response for this interaction.
+ ///
+ /// The request options for this async request.
+ /// A that represents the intitial response, or if there is no response.
+ public Task GetOriginalResponseAsync(RequestOptions options = null)
+ {
+ return InteractionHelper.GetOriginalResponseAsync(this.Discord, this.Channel, this, options);
+ }
+
///
/// Acknowledges this interaction with the .
///