A Discord shard manager to help with autoscaling shards based on load
On bot startup, make a request to /connect
with the header Authorization: <secret>
, where <secret>
is the same as SECRET
in your .env
Once you have connected with your shard, you'll need to make sure you make a request to /beat
every few seconds, less than MAX_SECONDS
specified in your .env
This will keep the shard alive and maintained in the manager, so new shards don't try to connect in its place.
Note: all endpoints require the Authorization: <secret>
header
import requests
headers = {
'Accept': 'application/json',
'Authorization': 'SECRET',
}
r = requests.get('/connect', headers = headers)
print(r.json())
Example responses
200 Response
{
"shard_id": 0,
"max_shards": 0,
"session_id": "string"
}
Status | Meaning | Description | Schema |
---|---|---|---|
200 | OK | Successful Response | ConnectConfirmed |
401 | Unauthorized | No Shards Available | None |
403 | Forbidden | Invalid Token | None |
422 | Unprocessable Entity | Validation Error | HTTPValidationError |
import requests
headers = {
'Accept': 'application/json',
'Authorization': 'SECRET',
}
r = requests.post('/beat', data={
'session_id': 'string'
}, headers = headers)
print(r.json())
Name | In | Type | Required | Description |
---|---|---|---|---|
session_id | data | string | true | Session ID provided by /connect |
guild_count | data | int | false | Number of guilds the shard sees |
latency | data | float | false | Current shard latency |
extra | data | Any | false | Extra data to store for shard |
Example responses
422 Response
{
"detail": [
{
"loc": [
"string"
],
"msg": "string",
"type": "string"
}
]
}
Status | Meaning | Description | Schema |
---|---|---|---|
204 | No Content | Successful Response | None |
401 | Unauthorized | No Shards Available | None |
403 | Forbidden | Invalid Token | None |
404 | Not Found | Session Not Found | None |
422 | Unprocessable Entity | Validation Error | HTTPValidationError |
{
"shard_id": 0,
"max_shards": 0,
"session_id": "string"
}
ConnectConfirmed
Name | Type | Required | Restrictions | Description |
---|---|---|---|---|
shard_id | integer | true | none | Shard ID to connect with |
max_shards | integer | true | none | Max number of shards |
session_id | string | true | none | Session ID for /beat |
{
"detail": [
{
"loc": [
"string"
],
"msg": "string",
"type": "string"
}
]
}
HTTPValidationError
Name | Type | Required | Restrictions | Description |
---|---|---|---|---|
detail | ValidationError | false | none | none |
{
"loc": [
"string"
],
"msg": "string",
"type": "string"
}
ValidationError
Name | Type | Required | Restrictions | Description |
---|---|---|---|---|
loc | [anyOf] | true | none | none |
anyOf
Name | Type | Required | Restrictions | Description |
---|---|---|---|---|
» anonymous | string | false | none | none |
or
Name | Type | Required | Restrictions | Description |
---|---|---|---|---|
» anonymous | integer | false | none | none |
continued
Name | Type | Required | Restrictions | Description |
---|---|---|---|---|
msg | string | true | none | none |
type | string | true | none | none |