Fix gateway interactions not running without bot scope. (#2217)
* Init * Implement public channelId
This commit is contained in:
@@ -2331,7 +2331,7 @@ namespace Discord.WebSocket
|
|||||||
|
|
||||||
SocketUser user = data.User.IsSpecified
|
SocketUser user = data.User.IsSpecified
|
||||||
? State.GetOrAddUser(data.User.Value.Id, (_) => SocketGlobalUser.Create(this, State, data.User.Value))
|
? State.GetOrAddUser(data.User.Value.Id, (_) => SocketGlobalUser.Create(this, State, data.User.Value))
|
||||||
: guild.AddOrUpdateUser(data.Member.Value);
|
: guild?.AddOrUpdateUser(data.Member.Value); // null if the bot scope isn't set, so the guild cannot be retrieved.
|
||||||
|
|
||||||
SocketChannel channel = null;
|
SocketChannel channel = null;
|
||||||
if(data.ChannelId.IsSpecified)
|
if(data.ChannelId.IsSpecified)
|
||||||
@@ -2345,10 +2345,14 @@ namespace Discord.WebSocket
|
|||||||
channel = CreateDMChannel(data.ChannelId.Value, user, State);
|
channel = CreateDMChannel(data.ChannelId.Value, user, State);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
|
if (guild != null) // The guild id is set, but the guild cannot be found as the bot scope is not set.
|
||||||
{
|
{
|
||||||
await UnknownChannelAsync(type, data.ChannelId.Value).ConfigureAwait(false);
|
await UnknownChannelAsync(type, data.ChannelId.Value).ConfigureAwait(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
// The channel isnt required when responding to an interaction, so we can leave the channel null.
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (data.User.IsSpecified)
|
else if (data.User.IsSpecified)
|
||||||
|
|||||||
@@ -19,13 +19,25 @@ namespace Discord.WebSocket
|
|||||||
/// Gets the <see cref="ISocketMessageChannel"/> this interaction was used in.
|
/// Gets the <see cref="ISocketMessageChannel"/> this interaction was used in.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <remarks>
|
/// <remarks>
|
||||||
/// If the channel isn't cached or the bot doesn't have access to it then
|
/// If the channel isn't cached, the bot scope isn't used, or the bot doesn't have access to it then
|
||||||
/// this property will be <see langword="null"/>.
|
/// this property will be <see langword="null"/>.
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
public ISocketMessageChannel Channel { get; private set; }
|
public ISocketMessageChannel Channel { get; private set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the ID of the channel this interaction was used in.
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// This property is exposed in cases where the bot scope is not provided, so the channel entity cannot be retrieved.
|
||||||
|
/// <br />
|
||||||
|
/// To get the channel, you can call <see cref="GetChannelAsync(RequestOptions)"/>
|
||||||
|
/// as this method makes a request for a <see cref="RestChannel"/> if nothing was found in cache.
|
||||||
|
/// </remarks>
|
||||||
|
public ulong? ChannelId { get; private set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the <see cref="SocketUser"/> who triggered this interaction.
|
/// Gets the <see cref="SocketUser"/> who triggered this interaction.
|
||||||
|
/// This property will be <see langword="null"/> if the bot scope isn't used.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public SocketUser User { get; private set; }
|
public SocketUser User { get; private set; }
|
||||||
|
|
||||||
@@ -62,8 +74,6 @@ namespace Discord.WebSocket
|
|||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public bool IsDMInteraction { get; private set; }
|
public bool IsDMInteraction { get; private set; }
|
||||||
|
|
||||||
private ulong? _channelId;
|
|
||||||
|
|
||||||
internal SocketInteraction(DiscordSocketClient client, ulong id, ISocketMessageChannel channel, SocketUser user)
|
internal SocketInteraction(DiscordSocketClient client, ulong id, ISocketMessageChannel channel, SocketUser user)
|
||||||
: base(client, id)
|
: base(client, id)
|
||||||
{
|
{
|
||||||
@@ -111,7 +121,7 @@ namespace Discord.WebSocket
|
|||||||
{
|
{
|
||||||
IsDMInteraction = !model.GuildId.IsSpecified;
|
IsDMInteraction = !model.GuildId.IsSpecified;
|
||||||
|
|
||||||
_channelId = model.ChannelId.ToNullable();
|
ChannelId = model.ChannelId.ToNullable();
|
||||||
|
|
||||||
Data = model.Data.IsSpecified
|
Data = model.Data.IsSpecified
|
||||||
? model.Data.Value
|
? model.Data.Value
|
||||||
@@ -396,12 +406,12 @@ namespace Discord.WebSocket
|
|||||||
if (Channel != null)
|
if (Channel != null)
|
||||||
return Channel;
|
return Channel;
|
||||||
|
|
||||||
if (!_channelId.HasValue)
|
if (!ChannelId.HasValue)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return (IMessageChannel)await Discord.GetChannelAsync(_channelId.Value, options).ConfigureAwait(false);
|
return (IMessageChannel)await Discord.GetChannelAsync(ChannelId.Value, options).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
catch(HttpException ex) when (ex.DiscordCode == DiscordErrorCode.MissingPermissions) { return null; } // bot can't view that channel, return null instead of throwing.
|
catch(HttpException ex) when (ex.DiscordCode == DiscordErrorCode.MissingPermissions) { return null; } // bot can't view that channel, return null instead of throwing.
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user