Fix attempts to fetch channels in interactions (#2090)
* fix attempts to fetch channels in interactions * remove test case
This commit is contained in:
@@ -7,6 +7,7 @@ using System.Threading.Tasks;
|
|||||||
using Model = Discord.API.Interaction;
|
using Model = Discord.API.Interaction;
|
||||||
using DataModel = Discord.API.ApplicationCommandInteractionData;
|
using DataModel = Discord.API.ApplicationCommandInteractionData;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
using Discord.Net;
|
||||||
|
|
||||||
namespace Discord.Rest
|
namespace Discord.Rest
|
||||||
{
|
{
|
||||||
@@ -130,7 +131,11 @@ namespace Discord.Rest
|
|||||||
|
|
||||||
if(Channel == null && model.ChannelId.IsSpecified)
|
if(Channel == null && model.ChannelId.IsSpecified)
|
||||||
{
|
{
|
||||||
Channel = (IRestMessageChannel)await discord.GetChannelAsync(model.ChannelId.Value);
|
try
|
||||||
|
{
|
||||||
|
Channel = (IRestMessageChannel)await discord.GetChannelAsync(model.ChannelId.Value);
|
||||||
|
}
|
||||||
|
catch(HttpException x) when(x.DiscordCode == DiscordErrorCode.MissingPermissions) { } // ignore
|
||||||
}
|
}
|
||||||
|
|
||||||
UserLocale = model.UserLocale.IsSpecified
|
UserLocale = model.UserLocale.IsSpecified
|
||||||
|
|||||||
@@ -2243,58 +2243,38 @@ namespace Discord.WebSocket
|
|||||||
channel = State.GetDMChannel(data.User.Value.Id);
|
channel = State.GetDMChannel(data.User.Value.Id);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (channel == null)
|
var guild = (channel as SocketGuildChannel)?.Guild;
|
||||||
|
if (guild != null && !guild.IsSynced)
|
||||||
{
|
{
|
||||||
var channelModel = await Rest.ApiClient.GetChannelAsync(data.ChannelId.Value);
|
await UnsyncedGuildAsync(type, guild.Id).ConfigureAwait(false);
|
||||||
|
|
||||||
if (data.GuildId.IsSpecified)
|
|
||||||
channel = SocketTextChannel.Create(State.GetGuild(data.GuildId.Value), State, channelModel);
|
|
||||||
else
|
|
||||||
channel = (SocketChannel)SocketChannel.CreatePrivate(this, State, channelModel);
|
|
||||||
|
|
||||||
State.AddChannel(channel);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (channel is ISocketMessageChannel textChannel)
|
|
||||||
{
|
|
||||||
var guild = (channel as SocketGuildChannel)?.Guild;
|
|
||||||
if (guild != null && !guild.IsSynced)
|
|
||||||
{
|
|
||||||
await UnsyncedGuildAsync(type, guild.Id).ConfigureAwait(false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var interaction = SocketInteraction.Create(this, data, channel as ISocketMessageChannel);
|
|
||||||
|
|
||||||
await TimedInvokeAsync(_interactionCreatedEvent, nameof(InteractionCreated), interaction).ConfigureAwait(false);
|
|
||||||
|
|
||||||
switch (interaction)
|
|
||||||
{
|
|
||||||
case SocketSlashCommand slashCommand:
|
|
||||||
await TimedInvokeAsync(_slashCommandExecuted, nameof(SlashCommandExecuted), slashCommand).ConfigureAwait(false);
|
|
||||||
break;
|
|
||||||
case SocketMessageComponent messageComponent:
|
|
||||||
if(messageComponent.Data.Type == ComponentType.SelectMenu)
|
|
||||||
await TimedInvokeAsync(_selectMenuExecuted, nameof(SelectMenuExecuted), messageComponent).ConfigureAwait(false);
|
|
||||||
if(messageComponent.Data.Type == ComponentType.Button)
|
|
||||||
await TimedInvokeAsync(_buttonExecuted, nameof(ButtonExecuted), messageComponent).ConfigureAwait(false);
|
|
||||||
break;
|
|
||||||
case SocketUserCommand userCommand:
|
|
||||||
await TimedInvokeAsync(_userCommandExecuted, nameof(UserCommandExecuted), userCommand).ConfigureAwait(false);
|
|
||||||
break;
|
|
||||||
case SocketMessageCommand messageCommand:
|
|
||||||
await TimedInvokeAsync(_messageCommandExecuted, nameof(MessageCommandExecuted), messageCommand).ConfigureAwait(false);
|
|
||||||
break;
|
|
||||||
case SocketAutocompleteInteraction autocomplete:
|
|
||||||
await TimedInvokeAsync(_autocompleteExecuted, nameof(AutocompleteExecuted), autocomplete).ConfigureAwait(false);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
await UnknownChannelAsync(type, data.ChannelId.Value).ConfigureAwait(false);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var interaction = SocketInteraction.Create(this, data, channel as ISocketMessageChannel);
|
||||||
|
|
||||||
|
await TimedInvokeAsync(_interactionCreatedEvent, nameof(InteractionCreated), interaction).ConfigureAwait(false);
|
||||||
|
|
||||||
|
switch (interaction)
|
||||||
|
{
|
||||||
|
case SocketSlashCommand slashCommand:
|
||||||
|
await TimedInvokeAsync(_slashCommandExecuted, nameof(SlashCommandExecuted), slashCommand).ConfigureAwait(false);
|
||||||
|
break;
|
||||||
|
case SocketMessageComponent messageComponent:
|
||||||
|
if (messageComponent.Data.Type == ComponentType.SelectMenu)
|
||||||
|
await TimedInvokeAsync(_selectMenuExecuted, nameof(SelectMenuExecuted), messageComponent).ConfigureAwait(false);
|
||||||
|
if (messageComponent.Data.Type == ComponentType.Button)
|
||||||
|
await TimedInvokeAsync(_buttonExecuted, nameof(ButtonExecuted), messageComponent).ConfigureAwait(false);
|
||||||
|
break;
|
||||||
|
case SocketUserCommand userCommand:
|
||||||
|
await TimedInvokeAsync(_userCommandExecuted, nameof(UserCommandExecuted), userCommand).ConfigureAwait(false);
|
||||||
|
break;
|
||||||
|
case SocketMessageCommand messageCommand:
|
||||||
|
await TimedInvokeAsync(_messageCommandExecuted, nameof(MessageCommandExecuted), messageCommand).ConfigureAwait(false);
|
||||||
|
break;
|
||||||
|
case SocketAutocompleteInteraction autocomplete:
|
||||||
|
await TimedInvokeAsync(_autocompleteExecuted, nameof(AutocompleteExecuted), autocomplete).ConfigureAwait(false);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "APPLICATION_COMMAND_CREATE":
|
case "APPLICATION_COMMAND_CREATE":
|
||||||
|
|||||||
@@ -17,6 +17,10 @@ namespace Discord.WebSocket
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// The <see cref="ISocketMessageChannel"/> this interaction was used in.
|
/// The <see cref="ISocketMessageChannel"/> this interaction was used in.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// If the channel isn't cached or the bot doesn't have access to it then
|
||||||
|
/// this property will be <see langword="null"/>.
|
||||||
|
/// </remarks>
|
||||||
public ISocketMessageChannel Channel { get; private set; }
|
public ISocketMessageChannel Channel { get; private set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user