Skip to content

Commit ff6464e

Browse files
fix: Unify API and gateway version constants (#3080)
* fix: Unify API and gateway version constants Introduced a new constants module to define API_VERSION and GATEWAY_VERSION, and updated gateway and HTTP modules to use these shared constants. This prevents version drift between REST and gateway usage. Updated the changelog to reflect this change. * style(pre-commit): auto fixes from pre-commit.com hooks --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent abe9856 commit ff6464e

4 files changed

Lines changed: 34 additions & 4 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ These changes are available on the `master` branch, but have not yet been releas
1919

2020
- Updated `Role.is_assignable()` to also check whether the bot has the `MANAGE_ROLES`
2121
permission. ([#3048](https://github.com/Pycord-Development/pycord/pull/3048))
22+
- Unified HTTP and voice gateway to use shared API version constants (v10) to avoid
23+
drift between REST and gateway versions.
24+
([#3080](https://github.com/Pycord-Development/pycord/pull/3080))
2225

2326
### Fixed
2427

discord/constants.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
"""
2+
The MIT License (MIT)
3+
4+
Copyright (c) 2021-present Pycord Development
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a
7+
copy of this software and associated documentation files (the "Software"),
8+
to deal in the Software without restriction, including without limitation
9+
the rights to use, copy, modify, merge, publish, distribute, sublicense,
10+
and/or sell copies of the Software, and to permit persons to whom the
11+
Software is furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in
14+
all copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17+
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22+
DEALINGS IN THE SOFTWARE.
23+
"""
24+
25+
from __future__ import annotations
26+
27+
API_VERSION: int = 10
28+
GATEWAY_VERSION: int = API_VERSION

discord/gateway.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141

4242
from . import utils
4343
from .activity import BaseActivity
44+
from .constants import GATEWAY_VERSION
4445
from .enums import SpeakingState
4546
from .errors import ConnectionClosed, InvalidArgument
4647

@@ -420,7 +421,6 @@ async def identify(self):
420421
},
421422
"compress": True,
422423
"large_threshold": 250,
423-
"v": 3,
424424
},
425425
}
426426

@@ -845,7 +845,7 @@ async def identify(self):
845845
@classmethod
846846
async def from_client(cls, client, *, resume=False, hook=None):
847847
"""Creates a voice websocket for the :class:`VoiceClient`."""
848-
gateway = f"wss://{client.endpoint}/?v=8"
848+
gateway = f"wss://{client.endpoint}/?v={GATEWAY_VERSION}&encoding=json"
849849
http = client._state.http
850850
socket = await http.ws_connect(gateway, compress=15)
851851
ws = cls(socket, loop=client.loop, hook=hook)

discord/http.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import aiohttp
4444

4545
from . import __version__, utils
46+
from .constants import API_VERSION
4647
from .errors import (
4748
DiscordServerError,
4849
Forbidden,
@@ -100,8 +101,6 @@
100101
MU = TypeVar("MU", bound="MaybeUnlock")
101102
Response = Coroutine[Any, Any, T]
102103

103-
API_VERSION: int = 10
104-
105104

106105
async def json_or_text(response: aiohttp.ClientResponse) -> dict[str, Any] | str:
107106
text = await response.text(encoding="utf-8")

0 commit comments

Comments
 (0)