Browse Source

Implement public channelId

pull/2217/head
Armano den Boef 3 years ago
parent
commit
1f0d639352
1 changed files with 14 additions and 5 deletions
  1. +14
    -5
      src/Discord.Net.WebSocket/Entities/Interaction/SocketInteraction.cs

+ 14
- 5
src/Discord.Net.WebSocket/Entities/Interaction/SocketInteraction.cs View File

@@ -24,6 +24,17 @@ namespace Discord.WebSocket
/// </remarks>
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>
/// Gets the <see cref="SocketUser"/> who triggered this interaction.
/// This property will be <see langword="null"/> if the bot scope isn't used.
@@ -63,8 +74,6 @@ namespace Discord.WebSocket
/// <inheritdoc/>
public bool IsDMInteraction { get; private set; }

private ulong? _channelId;

internal SocketInteraction(DiscordSocketClient client, ulong id, ISocketMessageChannel channel, SocketUser user)
: base(client, id)
{
@@ -112,7 +121,7 @@ namespace Discord.WebSocket
{
IsDMInteraction = !model.GuildId.IsSpecified;

_channelId = model.ChannelId.ToNullable();
ChannelId = model.ChannelId.ToNullable();

Data = model.Data.IsSpecified
? model.Data.Value
@@ -397,12 +406,12 @@ namespace Discord.WebSocket
if (Channel != null)
return Channel;

if (!_channelId.HasValue)
if (!ChannelId.HasValue)
return null;

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.
}


Loading…
Cancel
Save