Fix attempts to fetch channels in interactions (#2090)

* fix attempts to fetch channels in interactions

* remove test case
This commit is contained in:
Quin Lynch
2022-02-09 00:12:41 -04:00
committed by GitHub
parent 97e54e1047
commit 6290f75359
3 changed files with 39 additions and 50 deletions

View File

@@ -7,6 +7,7 @@ using System.Threading.Tasks;
using Model = Discord.API.Interaction;
using DataModel = Discord.API.ApplicationCommandInteractionData;
using Newtonsoft.Json;
using Discord.Net;
namespace Discord.Rest
{
@@ -129,9 +130,13 @@ namespace Discord.Rest
}
if(Channel == null && model.ChannelId.IsSpecified)
{
try
{
Channel = (IRestMessageChannel)await discord.GetChannelAsync(model.ChannelId.Value);
}
catch(HttpException x) when(x.DiscordCode == DiscordErrorCode.MissingPermissions) { } // ignore
}
UserLocale = model.UserLocale.IsSpecified
? model.UserLocale.Value

View File

@@ -2243,20 +2243,6 @@ namespace Discord.WebSocket
channel = State.GetDMChannel(data.User.Value.Id);
}
if (channel == null)
{
var channelModel = await Rest.ApiClient.GetChannelAsync(data.ChannelId.Value);
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)
{
@@ -2274,9 +2260,9 @@ namespace Discord.WebSocket
await TimedInvokeAsync(_slashCommandExecuted, nameof(SlashCommandExecuted), slashCommand).ConfigureAwait(false);
break;
case SocketMessageComponent messageComponent:
if(messageComponent.Data.Type == ComponentType.SelectMenu)
if (messageComponent.Data.Type == ComponentType.SelectMenu)
await TimedInvokeAsync(_selectMenuExecuted, nameof(SelectMenuExecuted), messageComponent).ConfigureAwait(false);
if(messageComponent.Data.Type == ComponentType.Button)
if (messageComponent.Data.Type == ComponentType.Button)
await TimedInvokeAsync(_buttonExecuted, nameof(ButtonExecuted), messageComponent).ConfigureAwait(false);
break;
case SocketUserCommand userCommand:
@@ -2290,12 +2276,6 @@ namespace Discord.WebSocket
break;
}
}
else
{
await UnknownChannelAsync(type, data.ChannelId.Value).ConfigureAwait(false);
return;
}
}
break;
case "APPLICATION_COMMAND_CREATE":
{

View File

@@ -17,6 +17,10 @@ namespace Discord.WebSocket
/// <summary>
/// The <see cref="ISocketMessageChannel"/> this interaction was used in.
/// </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; }
/// <summary>