disco.state
Classes
StackMessage
Inherits From namedtuple
A message stored on a stack inside of the state object, used for tracking previously sent messages in channels.
Attributes
Name | Type | Description |
---|---|---|
id | snowflake |
the id of the message |
channel_id | snowflake |
the id of the channel this message was sent in |
author_id | snowflake |
the id of the author of this message |
StateConfig
Inherits From Config
A configuration object for determining how the State tracking behaves.
Attributes
Name | Type | Description |
---|---|---|
track_messages | bool |
Whether the state store should keep a buffer of previously sent messages. Message tracking allows for multiple higher-level shortcuts and can be highly useful when developing bots that need to delete their own messages. Message tracking is implemented using a deque and a namedtuple, meaning it should generally not have a high impact on memory, however users who find they do not need and may be experiencing memory pressure can disable this feature entirely using this attribute. |
track_messages_size | int |
The size of the messages deque for each channel. This value can be used to calculate the total number of possible `StackMessage` objects kept in memory, simply: `total_messages_size * total_channels`. This value can be tweaked based on usage and to help prevent memory pressure. |
sync_guild_members | bool |
If true, guilds will be automatically synced when they are initially loaded or joined. Generally this setting is OK for smaller bots, however bots in over 50 guilds will notice this operation can take a while to complete. |
State
The State class is used to track global state based on events emitted from
the GatewayClient
. State tracking is a core component of the Disco client,
providing the mechanism for most of the higher-level utility functions.
Attributes
Name | Type | Description |
---|---|---|
EVENTS | list(str) |
A list of all events the State object binds to |
client | `disco.client.Client` |
The Client instance this state is attached to |
config | `StateConfig` |
The configuration for this state instance |
me | `User` |
The currently logged in user |
dms | dict(snowflake, `Channel`) |
Mapping of all known DM Channels |
guilds | dict(snowflake, `Guild`) |
Mapping of all known/loaded Guilds |
channels | dict(snowflake, `Channel`) |
Weak mapping of all known/loaded Channels |
users | dict(snowflake, `User`) |
Weak mapping of all known/loaded Users |
voice_states | dict(str, `VoiceState`) |
Weak mapping of all known/active Voice States |
messages | Optional[dict(snowflake, deque)] |
Mapping of channel ids to deques containing `StackMessage` objects |
Functions
init(self, client, config)
unbind(self
)
Unbinds all bound event listeners for this state object.
bind(self
)
Binds all events for this state object, storing the listeners for later