/// <summary> Specifies the type of token to use with the client. </summary>
public enum TokenType
{
[Obsolete("User logins are deprecated and may result in a ToS strike against your account - please see https://github.com/RogueException/Discord.Net/issues/827", error: true)]
/// <exception cref="ArgumentOutOfRangeException">Message content is too long, length must be less or equal to <see cref="DiscordConfig.MaxMessageSize"/>.</exception>
/// <exception cref="InvalidOperationException">This operation may only be called with a <see cref="TokenType.Webhook"/> token.</exception>
Preconditions.AtMost(args.Embeds.Value.Length, 10, nameof(args.Embeds), "A max of 10 Embeds are allowed.");
if (args.Content.IsSpecified && args.Content.Value.Length > DiscordConfig.MaxMessageSize)
throw new ArgumentException(message: $"Message content is too long, length must be less or equal to {DiscordConfig.MaxMessageSize}.", paramName: nameof(args.Content));
/// <exception cref="ArgumentOutOfRangeException">Message content is too long, length must be less or equal to <see cref="DiscordConfig.MaxMessageSize"/>.</exception>
/// <exception cref="ArgumentOutOfRangeException">Message content is too long, length must be less or equal to <see cref="DiscordConfig.MaxMessageSize"/>.</exception>
public override IReadOnlyCollection<ISocketPrivateChannel> PrivateChannels => GetPrivateChannels().ToReadOnlyCollection(GetPrivateChannelCount);
public IReadOnlyCollection<DiscordSocketClient> Shards => _shards;
/// <inheritdoc />
[Obsolete("This property is obsolete, use the GetVoiceRegionsAsync method instead.")]
public override IReadOnlyCollection<RestVoiceRegion> VoiceRegions => _shards[0].VoiceRegions;
/// <summary>
/// Provides access to a REST-only client with a shared state from this client.
/// </summary>
public override DiscordSocketRestClient Rest => _shards[0].Rest;
public override DiscordSocketRestClient Rest => _shards?[0].Rest;
public override SocketSelfUser CurrentUser { get => _shards?.FirstOrDefault(x => x.CurrentUser != null)?.CurrentUser; protected set => throw new InvalidOperationException(); }
/// <summary> Creates a new REST/WebSocket Discord client. </summary>
public DiscordShardedClient() : this(null, new DiscordSocketConfig()) { }
var data = (payload as JToken).ToObject<API.Gateway.Reaction>(_serializer);
if (State.GetChannel(data.ChannelId) is ISocketMessageChannel channel)
{
var cachedMsg = channel.GetCachedMessage(data.MessageId) as SocketUserMessage;
bool isCached = cachedMsg != null;
var user = await channel.GetUserAsync(data.UserId, CacheMode.CacheOnly).ConfigureAwait(false);
var channel = GetChannel(data.ChannelId) as ISocketMessageChannel;
var optionalMsg = !isCached
? Optional.Create<SocketUserMessage>()
: Optional.Create(cachedMsg);
var optionalUser = user is null
? Optional.Create<IUser>()
: Optional.Create(user);
var cachedMsg = channel?.GetCachedMessage(data.MessageId) as SocketUserMessage;
bool isMsgCached = cachedMsg != null;
IUser user = null;
if (channel != null)
user = await channel.GetUserAsync(data.UserId, CacheMode.CacheOnly).ConfigureAwait(false);
var reaction = SocketReaction.Create(data, channel, optionalMsg, optionalUser);
var cacheable = new Cacheable<IUserMessage, ulong>(cachedMsg, data.MessageId, isCached, async () => await channel.GetMessageAsync(data.MessageId).ConfigureAwait(false) as IUserMessage);
var optionalMsg = !isMsgCached
? Optional.Create<SocketUserMessage>()
: Optional.Create(cachedMsg);
cachedMsg?.AddReaction(reaction);
if (data.Member.IsSpecified)
{
var guild = (channel as SocketGuildChannel)?.Guild;
var data = (payload as JToken).ToObject<API.Gateway.Reaction>(_serializer);
if (State.GetChannel(data.ChannelId) is ISocketMessageChannel channel)
{
var cachedMsg = channel.GetCachedMessage(data.MessageId) as SocketUserMessage;
bool isCached = cachedMsg != null;
var user = await channel.GetUserAsync(data.UserId, CacheMode.CacheOnly).ConfigureAwait(false);
var optionalMsg = !isCached
? Optional.Create<SocketUserMessage>()
: Optional.Create(cachedMsg);
var channel = GetChannel(data.ChannelId) as ISocketMessageChannel;
var optionalUser = user is null
? Optional.Create<IUser>()
: Optional.Create(user);
var cachedMsg = channel?.GetCachedMessage(data.MessageId) as SocketUserMessage;
bool isMsgCached = cachedMsg != null;
IUser user = null;
if (channel != null)
user = await channel.GetUserAsync(data.UserId, CacheMode.CacheOnly).ConfigureAwait(false);
else if (!data.GuildId.IsSpecified)
user = GetUser(data.UserId);
var reaction = SocketReaction.Create(data, channel, optionalMsg, optionalUser);
var cacheable = new Cacheable<IUserMessage, ulong>(cachedMsg, data.MessageId, isCached, async () => await channel.GetMessageAsync(data.MessageId).ConfigureAwait(false) as IUserMessage);
var data = (payload as JToken).ToObject<RemoveAllReactionsEvent>(_serializer);
if (State.GetChannel(data.ChannelId) is ISocketMessageChannel channel)
var channel = GetChannel(data.ChannelId) as ISocketMessageChannel;
var cacheableChannel = new Cacheable<IMessageChannel, ulong>(channel, data.ChannelId, channel != null, async () => await GetChannelAsync(data.ChannelId).ConfigureAwait(false) as IMessageChannel);
var cachedMsg = channel?.GetCachedMessage(data.MessageId) as SocketUserMessage;
bool isMsgCached = cachedMsg != null;
var cacheableMsg = new Cacheable<IUserMessage, ulong>(cachedMsg, data.MessageId, isMsgCached, async () =>
{
var cachedMsg = channel.GetCachedMessage(data.MessageId) as SocketUserMessage;
bool isCached = cachedMsg != null;
var cacheable = new Cacheable<IUserMessage, ulong>(cachedMsg, data.MessageId, isCached, async () => (await channel.GetMessageAsync(data.MessageId).ConfigureAwait(false)) as IUserMessage);
var channelObj = await cacheableChannel.GetOrDownloadAsync().ConfigureAwait(false);
return await channelObj.GetMessageAsync(data.MessageId).ConfigureAwait(false) as IUserMessage;
var data = (payload as JToken).ToObject<API.Gateway.RemoveAllReactionsForEmoteEvent>(_serializer);
if (State.GetChannel(data.ChannelId) is ISocketMessageChannel channel)
{
var cachedMsg = channel.GetCachedMessage(data.MessageId) as SocketUserMessage;
bool isCached = cachedMsg != null;
var optionalMsg = !isCached
? Optional.Create<SocketUserMessage>()
: Optional.Create(cachedMsg);
var channel = GetChannel(data.ChannelId) as ISocketMessageChannel;
var cacheable = new Cacheable<IUserMessage, ulong>(cachedMsg, data.MessageId, isCached, async () => await channel.GetMessageAsync(data.MessageId).ConfigureAwait(false) as IUserMessage);
var emote = data.Emoji.ToIEmote();
var cachedMsg = channel?.GetCachedMessage(data.MessageId) as SocketUserMessage;
/// Gets or sets the behavior for <see cref="BaseSocketClient.MessageDeleted"/> on bulk deletes.
/// </summary>
/// <remarks>
/// <para>
/// If <c>true</c>, the <see cref="BaseSocketClient.MessageDeleted"/> event will not be raised for bulk
/// deletes, and only the <see cref="BaseSocketClient.MessagesBulkDeleted"/> will be raised. If <c>false</c>
/// , both events will be raised.
/// </para>
/// <para>
/// If unset, both events will be raised, but a warning will be raised the first time a bulk delete event is
/// received.
/// </para>
/// </remarks>
public bool? ExclusiveBulkDelete { get; set; } = null;
/// <summary>
/// Gets or sets enabling dispatching of guild subscription events e.g. presence and typing events.
/// This is not used if <see cref="GatewayIntents"/> are provided.
/// </summary>
public bool GuildSubscriptions { get; set; } = true;
/// <summary>
/// Gets or sets the maximum identify concurrency.
/// </summary>
@@ -172,14 +150,15 @@ namespace Discord.WebSocket
private int maxWaitForGuildAvailable = 10000;
/// <summary>
/// Gets or sets gateway intents to limit what events are sent from Discord. Allows for more granular control than the <see cref="GuildSubscriptions"/> property.
/// Gets or sets gateway intents to limit what events are sent from Discord.
/// The default is <see cref="GatewayIntents.AllUnprivileged"/>.
/// Gets a collection of messages in this channel.
/// </summary>
@@ -103,7 +105,7 @@ namespace Discord.WebSocket
/// Paged collection of messages.
/// </returns>
public IAsyncEnumerable<IReadOnlyCollection<IMessage>> GetMessagesAsync(ulong fromMessageId, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch, RequestOptions options = null)
/// Gets a collection of messages in this channel.
/// </summary>
@@ -119,16 +121,16 @@ namespace Discord.WebSocket
/// Paged collection of messages.
/// </returns>
public IAsyncEnumerable<IReadOnlyCollection<IMessage>> GetMessagesAsync(IMessage fromMessage, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch, RequestOptions options = null)
Thank you for your continuous support to the Openl Qizhi Community AI Collaboration Platform. In order to protect your usage rights and ensure network security, we updated the Openl Qizhi Community AI Collaboration Platform Usage Agreement in January 2024. The updated agreement specifies that users are prohibited from using intranet penetration tools. After you click "Agree and continue", you can continue to use our services. Thank you for your cooperation and understanding.