API Overview¶
This is an overview containing some important classes and functions.
Contents
Client¶
-
create_client
(http_uri, web_socket_uri, password, user_id, *, state=None)[source]¶ Create a new combined Andesite client.
- Parameters
- Return type
- Returns
A new combined client with
HTTPBase
andWebSocketBase
as its clients.
Pool¶
-
create_pool
(http_nodes, web_socket_nodes, *, user_id, state=None, http_pool_kwargs=None, web_socket_pool_kwargs=None)[source]¶ Create an
Client
with client pools.Uses
HTTPBase
andWebSocketBase
which are contained inHTTPPoolBase
andWebSocketPoolBase
pools respectively.- Parameters
http_nodes (
Iterable
[Tuple
[Union
[str
,URL
],Optional
[str
]]]) – Tuples of [uri, password] for each REST node to connect to.web_socket_nodes (
Iterable
[Tuple
[Union
[str
,URL
],Optional
[str
]]]) – Tuples of [uri, password] for each WebSocket node to connect to.user_id (
int
) – Bot’s user id.state (
Union
[AbstractState
,bool
,None
]) – State handler to use for the pools. Defaults toState
, because a state handler is required for node migration to work. You can passFalse
to disable state handling though.http_pool_kwargs (
Optional
[Mapping
[str
,Any
]]) – Additional keyword arguments to pass to the http pool constructor.web_socket_pool_kwargs (
Optional
[Mapping
[str
,Any
]]) – Additional keyword arguments to pass to the web socket pool constructor.
- Return type
- Returns
A combined Andesite client operation on an http pool and a web socket pool.
Models¶
Player/Track¶
-
class
Player
(time, position, paused, volume, filters, frame, mixer, mixer_enabled)[source]¶ -
mixer
¶ map of mixer player id -> mixer player
- Type
MixerMap
-
-
class
LoadedTrack
(load_type, tracks, playlist_info, cause=None, severity=None)[source]¶ Result provided by a load track request.
-
playlist_info
¶ metadata of the loaded playlist
- Type
Optional[PlaylistInfo]
This class provides the magic methods
__bool__
and__len__
which operate in respect totracks
.-
get_selected_track
()[source]¶ Get the selected track.
“Selected” means that either the result is a playlist with an entry selected (
PlaylistInfo.selected_track
), or the result is aLoadType.TRACK_LOADED
result (in which case the first and only track is returned).All other cases will return in
None
being returned.
-
-
class
LoadType
[source]¶ Load type of a
LoadedTrack
-
class
TrackInfo
(track, info)[source]¶ Track info represents a track and its metadata.
-
info
¶ metadata of the track
- Type
-
-
class
TrackMetadata
(class_name, title, author, length, identifier, uri, is_stream, is_seekable, position)[source]¶ Additional information for a track.
author of the track
- Type
-
length
¶ duration of the track, in seconds. Set to
None
if it’s a stream. Andesite would normally return 2^63 - 1 (Long.MAX_VALUE), but that value doesn’t have any significance in Python so it’s represented with something more meaningful.- Type
Optional[float]
Whether or not the author is unknown.
Uses constant
UNKNOWN_ARTIST
to check against.Keep in mind that there is no way to detect whether the author’s name just happens to coincide with the
UNKNOWN_ARTIST
text. Use with caution.- Return type
Command Operations¶
-
class
Play
(track, start=None, end=None, pause=None, volume=None, no_replace=False)[source]¶ Operation playing a track.
-
class
FilterUpdate
(filters)[source]¶ Operation adjusting the filter settings.
See also
This class inherits from
FilterMap
.-
clear
() → None. Remove all items from D.¶
-
get
(k[, d]) → D[k] if k in D, else d. d defaults to None.¶
-
get_filter
(name, cls)¶ Get the filter with the name.
-
items
() → a set-like object providing a view on D's items¶
-
keys
() → a set-like object providing a view on D's keys¶
-
pop
(k[, d]) → v, remove specified key and return the corresponding value.¶ If key is not found, d is returned if given, otherwise KeyError is raised.
-
popitem
() → (k, v), remove and return some (key, value) pair¶ as a 2-tuple; but raise KeyError if D is empty.
-
set_filter
(andesite_filter)¶ Set the value for a filter.
- Parameters
andesite_filter (
Filter
) – Filter to set- Return type
None
-
setdefault
(k[, d]) → D.get(k,d), also set D[k]=d if k not in D¶
-
update
([E, ]**F) → None. Update D from mapping/iterable E and F.¶ If E present and has a .keys() method, does: for k in E: D[k] = E[k] If E present and lacks .keys() method, does: for (k, v) in E: D[k] = v In either case, this is followed by: for k, v in F.items(): D[k] = v
-
values
() → an object providing a view on D's values¶
-
property
volume
¶ Volume filter settings
- Return type
-
-
class
Update
(pause=None, position=None, volume=None, filters=None)[source]¶ Operation providing an update for the current track.
-
filters
¶ configuration for the filters
- Type
Optional[FilterUpdate]
-
Responses¶
-
class
PlayerUpdate
(user_id, guild_id, state)[source]¶ Player update sent by Andesite for active players.
-
state
¶ State of the player.
None
if no player exists yet.- Type
Optional[andesite.Player]
-
-
class
PongResponse
(user_id, guild_id)[source]¶ Simple pong response sent as a response to ping requests.
Events¶
-
class
WebSocketConnectEvent
(client)[source]¶ Event dispatched when a connection has been established.
-
client
¶ Web socket client which connected.
-
-
class
WebSocketDisconnectEvent
(client, deliberate)[source]¶ Event dispatched when a client was disconnected.
-
client
¶ Web socket client which connected.
-
-
class
RawMsgReceiveEvent
(client, body)[source]¶ Event emitted when a web socket message is received.
-
client
¶ Web socket client that received the message.
- Type
-
-
class
RawMsgSendEvent
(client, guild_id, op, body)[source]¶ Event dispatched before a web socket message is sent.
It’s important to note that this is not a receipt of a message being sent, this event is dispatched even if the message fails to send.
-
client
¶ Web socket client that received the message.
-
-
class
TrackStartEvent
(type, user_id, guild_id, track)[source]¶ Event emitted when a new track starts playing.
-
class
TrackEndEvent
(type, user_id, guild_id, track, reason, may_start_next)[source]¶ Event emitted when a track ended.
-
reason
¶ Reason why a track stopped playing.
- Type
-
may_start_next
¶ Indicates whether a new track should be started on receiving this event. If this is
False
, either this event is already triggered because another track started (TrackEndReason.REPLACED
) or because the player is stopped (TrackEndReason.STOPPED
,TrackEndReason.CLEANUP
).- Type
-
-
class
TrackEndReason
[source]¶ Reason why a track stopped playing.
See also
-
FINISHED
¶ Usually caused by the track reaching the end, however it will also be used when it ends due to an exception.
-
LOAD_FAILED
¶ Track failed to start, throwing an exception before providing any audio.
-
STOPPED
¶ Track was stopped due to the player being stopped.
-
REPLACED
¶ Track stopped playing because a new track started playing.
-
CLEANUP
¶ Track was stopped because the cleanup threshold for the audio player was reached.
-
-
class
TrackStuckEvent
(type, user_id, guild_id, track, threshold)[source]¶ Event emitted when a track is stuck.
-
class
TrackExceptionEvent
(type, user_id, guild_id, track, error, exception)[source]¶ Event emitted when there’s an error.
Filters¶
-
class
Equalizer
(enabled=True, bands=<factory>)[source]¶ -
bands
¶ array of bands to configure
- Type
List[EqualizerBand]
-
get_band
(band, create=True)[source]¶ Get the specified band from the bands list.
If the band doesn’t exist it is created. If you don’t want to automatically create a band, pass
create=False
.- Parameters
- Return type
-
set_band_gain
(band, gain)[source]¶ Set the gain of a band to the specified value.
If the band does not exist it is created.
- Parameters
- Raises
ValueError – if the provided gain is invalid.
- Return type
None
-
reset
()¶ Reset the filter settings back to their default values.
- Return type
None
-
-
class
EqualizerBand
(band, gain=0.0)[source]¶ -
-
set_band
(value)[source]¶ Setter for
band
which performs a value check.- Parameters
value (
int
) – Value to set for the band. ( [0, 14] )- Raises
ValueError – if the provided value is invalid.
- Return type
None
-
set_gain
(value)[source]¶ Setter for
gain
which performs a value check.- Parameters
value (
float
) – Value to set for the gain. ( [-0.25, 1] )- Raises
ValueError – if the provided value is invalid.
- Return type
None
-
-
class
Karaoke
(enabled=True, level=1.0, mono_level=1.0, filter_band=220.0, filter_width=100.0)[source]¶ -
-
reset
()¶ Reset the filter settings back to their default values.
- Return type
None
-
-
class
Timescale
(enabled=True, speed=1.0, pitch=1.0, rate=1.0)[source]¶ -
-
set_speed
(value)[source]¶ Setter for
speed
which performs a value check.- Parameters
value (
float
) – Value to set for the speed. ( (0, INF] )- Raises
ValueError – if the provided value is invalid.
- Return type
None
-
set_pitch
(value)[source]¶ Setter for
pitch
which performs a value check.- Parameters
value (
float
) – Value to set for the pitch. ( (0, INF] )- Raises
ValueError – if the provided value is invalid.
- Return type
None
-
set_rate
(value)[source]¶ Setter for
rate
which performs a value check.- Parameters
value (
float
) – Value to set for the rate. ( (0, INF] )- Raises
ValueError – if the provided value is invalid.
- Return type
None
-
reset
()¶ Reset the filter settings back to their default values.
- Return type
None
-
-
class
Tremolo
(enabled=True, frequency=2.0, depth=0.5)[source]¶ -
-
set_frequency
(value)[source]¶ Setter for
frequency
which performs a value check.- Parameters
value (
float
) – Value to set for the frequency. ( (0, INF] )- Raises
ValueError – if the provided value is invalid.
- Return type
None
-
set_depth
(value)[source]¶ Setter for
depth
which performs a value check.- Parameters
value (
float
) – Value to set for the depth. ( (0, 1] )- Raises
ValueError – if the provided value is invalid.
- Return type
None
-
reset
()¶ Reset the filter settings back to their default values.
- Return type
None
-
-
class
Vibrato
(enabled=True, frequency=2.0, depth=0.5)[source]¶ -
-
set_frequency
(value)[source]¶ Setter for
frequency
which performs a value check.- Parameters
value (
float
) – Value to set for the frequency. ( (0, 14] )- Raises
ValueError – if the provided value is invalid.
- Return type
None
-
set_depth
(value)[source]¶ Setter for
depth
which performs a value check.- Parameters
value (
float
) – Value to set for the depth. ( (0, 1] )- Raises
ValueError – if the provided value is invalid.
- Return type
None
-
reset
()¶ Reset the filter settings back to their default values.
- Return type
None
-
-
class
VolumeFilter
(enabled=True, volume=1.0)[source]¶ Volume filter settings.
-
reset
()¶ Reset the filter settings back to their default values.
- Return type
None
-
-
class
FilterMap
(filters)[source]¶ Custom mapping type for filters.
Theoretically this is just a wrapper around the
filters
dictionary which contains the actual filter data. The class exposes the known filters as properties, but it also supports unknown filters should the library become outdated.You can also use this as a wrapper for an existing filter dict.
-
clear
() → None. Remove all items from D.¶
-
get
(k[, d]) → D[k] if k in D, else d. d defaults to None.¶
-
items
() → a set-like object providing a view on D's items¶
-
keys
() → a set-like object providing a view on D's keys¶
-
pop
(k[, d]) → v, remove specified key and return the corresponding value.¶ If key is not found, d is returned if given, otherwise KeyError is raised.
-
popitem
() → (k, v), remove and return some (key, value) pair¶ as a 2-tuple; but raise KeyError if D is empty.
-
setdefault
(k[, d]) → D.get(k,d), also set D[k]=d if k not in D¶
-
update
([E, ]**F) → None. Update D from mapping/iterable E and F.¶ If E present and has a .keys() method, does: for k in E: D[k] = E[k] If E present and lacks .keys() method, does: for (k, v) in E: D[k] = v In either case, this is followed by: for k, v in F.items(): D[k] = v
-
values
() → an object providing a view on D's values¶
-
property
volume
¶ Volume filter settings
- Return type
-
Debug¶
Debug models for Andesite.
These models are used in either Stats
which represents the Andesite
stats returned by WebSocketInterface.get_stats
or Error
which is
used to represent an Andesite error.
-
class
StackFrame
(class_loader, module_name, module_version, class_name, method_name, file_name, line_number, pretty)[source]¶ Andesite stack frame.
Can be found in
Error.stack
.
-
class
Error
(class_name, message, stack, suppressed, cause)[source]¶ Andesite error.
You can convert the Andesite error data into a Python exception using the
as_python_exception
method and theraise_python_exception
to raise it.-
stack
¶ stacktrace of the error
- Type
List[StackFrame]
-
as_python_exception
()[source]¶ Create an
AndesiteException
which can be raised.If
cause
is notNone
it is added to the exception.- Return type
-
raise_error
()[source]¶ Raise the Andesite error as an
AndesiteException
.- Raises
AndesiteException – Generated using the
as_python_exception
method.- Return type
-
-
exception
AndesiteException
(class_name, message, stack, suppressed)[source]¶ Andesite’s
Error
represented as python exceptions.-
stack
¶ cause of the error
- Type
List[StackFrame]
-
-
class
PlayersStats
(total, playing)[source]¶ Players statistics sent by Andesite.
See also
This statistic can be found in
Stats
which is retrieved from Andesite by the clients. BothHTTP
andWebSocket
are able to get them.
-
class
RuntimeVMStats
(name, vendor, version)[source]¶ VM statistics.
See also
This statistic can be found in
Stats
which is retrieved from Andesite by the clients. BothHTTP
andWebSocket
are able to get them.
-
class
RuntimeSpecStats
(name, vendor, version)[source]¶ Spec statistics.
See also
This statistic can be found in
Stats
which is retrieved from Andesite by the clients. BothHTTP
andWebSocket
are able to get them.
-
class
RuntimeVersionStats
(feature, interim, update, patch, pre, build, optional)[source]¶ Version information stats.
See also
This statistic can be found in
Stats
which is retrieved from Andesite by the clients. BothHTTP
andWebSocket
are able to get them.
-
class
RuntimeStats
(uptime, pid, management_spec_version, name, vm, spec, version)[source]¶ Runtime statistics.
-
vm
¶ - Type
-
spec
¶ - Type
-
version
¶ - Type
See also
This statistic can be found in
Stats
which is retrieved from Andesite by the clients. BothHTTP
andWebSocket
are able to get them.-
-
class
OSStats
(processors, name, arch, version)[source]¶ OS statistics.
See also
This statistic can be found in
Stats
which is retrieved from Andesite by the clients. BothHTTP
andWebSocket
are able to get them.
-
class
CPUStats
(andesite, system)[source]¶ CPU statistics.
See also
This statistic can be found in
Stats
which is retrieved from Andesite by the clients. BothHTTP
andWebSocket
are able to get them.
-
class
ThreadStats
(running, daemon, peak, total_started)[source]¶ Thread statistics.
See also
This statistic can be found in
Stats
which is retrieved from Andesite by the clients. BothHTTP
andWebSocket
are able to get them.
-
class
CompilationStats
(name, total_time)[source]¶ Compilation statistics.
See also
This statistic can be found in
Stats
which is retrieved from Andesite by the clients. BothHTTP
andWebSocket
are able to get them.
-
class
MemoryCommonUsageStats
(init, used, committed, max)[source]¶ Memory usage statistics.
See also
This statistic can be found in
Stats
which is retrieved from Andesite by the clients. BothHTTP
andWebSocket
are able to get them.
-
class
MemoryStats
(pending_finalization, heap, non_heap)[source]¶ Memory statistics.
-
heap
¶
-
non_heap
¶
See also
This statistic can be found in
Stats
which is retrieved from Andesite by the clients. BothHTTP
andWebSocket
are able to get them.-
-
class
GCStats
(name, collection_count, collection_time, pools)[source]¶ Garbage collection statistics.
See also
This statistic can be found in
Stats
which is retrieved from Andesite by the clients. BothHTTP
andWebSocket
are able to get them.
-
class
MemoryPoolStats
(name, type, collection_usage, collection_usage_threshold, collection_usage_threshold_count, peak_usage, usage, usage_threshold, usage_threshold_count, managers)[source]¶ Memory pool statistics.
-
collection_usage
¶ - Type
Optional[MemoryHeapStats]
-
peak_usage
¶
-
usage
¶
See also
This statistic can be found in
Stats
which is retrieved from Andesite by the clients. BothHTTP
andWebSocket
are able to get them.-
-
class
MemoryManagerStats
(name, pools)[source]¶ Memory manager statistics.
See also
This statistic can be found in
Stats
which is retrieved from Andesite by the clients. BothHTTP
andWebSocket
are able to get them.
-
class
FrameStats
(user, guild, success, loss)[source]¶ Frame statistics for a guild player.
See also
This statistic can be found in
Stats
which is retrieved from Andesite by the clients. BothHTTP
andWebSocket
are able to get them.
-
class
Stats
(players, runtime, os, cpu, class_loading, thread, compilation, memory, gc, memory_pools, memory_managers, frame_stats)[source]¶ Statistics sent by Andesite
-
players
¶ Player statistics
- Type
-
runtime
¶ Runtime statistics
- Type
-
class_loading
¶ Class loading statistics
- Type
-
thread
¶ Thread statistics
- Type
-
compilation
¶ Compilation statistics
- Type
-
memory
¶ Memory statistics
- Type
-
memory_pools
¶ Memory pool statistics
- Type
List[MemoryPoolStats]
-
memory_managers
¶ Memory manager statistics
- Type
List[MemoryManagerStats]
-
frame_stats
¶ Frame statistics
- Type
List[FrameStats]
-
Exceptions¶
-
exception
AndesiteException
(class_name, message, stack, suppressed)[source]¶ Bases:
Exception
Andesite’s
Error
represented as python exceptions.-
stack
¶ cause of the error
- Type
List[StackFrame]
-
-
exception
PoolException
(pool)[source]¶ Bases:
Exception
Pool exceptions.
-
pool
¶ Pool which raised the error
- Type
-
-
exception
PoolEmptyError
(pool)[source]¶ Bases:
andesite.pools.PoolException
Raised when a pool is empty but shouldn’t be.
discord.py integration¶
-
add_voice_server_update_handler
(discord_client, andesite_client)[source]¶ Add a voice server update listener to the discord client.
- Parameters
discord_client (
Client
) – Discord client to add the listener to.andesite_client (
WebSocketInterface
) – Andesite web socket client to use to send the voice server update.
This will listen to socket responses using the discord client and trigger
WebSocketInterface.voice_server_update
.- Return type
None
-
remove_voice_server_update_handler
(discord_client, andesite_client)[source]¶ Remove the socket response handler added by
add_voice_server_update_handler
.- Parameters
discord_client (
Client
) – Discord client to remove listener from.andesite_client (
WebSocketInterface
) – Andesite web socket client to use to send the voice server update.
- Return type
None
-
async
connect_voice_channel
(client, *args, **kwargs)[source]¶ Connect to a voice channel.
This function has two signatures, you can either call it with a
VoiceChannel
, or provide a guild / guild id and the voice channel id.- Return type
None
-
async
disconnect_voice_channel
(client, guild)[source]¶ Disconnect from the current voice channel.
- Return type
None
-
create_region_comparator
(discord_client, *, region_comp=None)[source]¶ Create a region comparator which compares the guild region with the node region.
You can use the created comparator for the
WebSocketPool
.- Parameters
- Return type
- Returns
Region comparator which uses region_comp to compare guild region with node region.
-
compare_regions
(a_region, b_region)[source]¶ Compare two region names.
The order of the provided regions is irrelevant.
- Parameters
- Return type
- Returns
0 if the regions can’t be properly compared (ex: Node region unknown or guild id unknown). If the regions can be compared the result is the sum of the following points:
2 points if both regions are in the same country
1 point if both regions are in the same part of a country (ex: us_west) (This point is also awarded if both regions don’t specify a country part)