Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/docs-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
- name: Install dependencies
run: |
python -m pip install -U pip
pip install ".[docs]"
pip install ".[docs,voice]"
- name: "Check Links"
if: ${{ github.event_name == 'schedule' || inputs.with_linkcheck }}
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/docs-json-export.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
id: install-deps
run: |
python -m pip install -U pip
pip install ".[docs]"
pip install ".[docs,voice]"
pip install beautifulsoup4
- name: Build Sphinx HTML docs
id: build-sphinx
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/lib-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ jobs:
run: |
python -m pip install --upgrade pip
pip install . --group dev
pip install .[voice]

- name: "Run tests"
run: tox
Expand Down
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -194,3 +194,9 @@ docs/build/linkcheck
/build/
/vscode/
remote-release.yml
logs/
recordings/
*.ps1
*.ogg
*.mp3
*.pcm
1 change: 1 addition & 0 deletions .readthedocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ python:
path: .
extra_requirements:
- docs
- voice
2 changes: 1 addition & 1 deletion discord/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@


from . import abc, opus, sinks, ui, utils
from ._voice_aliases import *
from .activity import *
from .appinfo import *
from .application_role_connection import *
Expand Down Expand Up @@ -74,7 +75,6 @@
from .template import *
from .threads import *
from .user import *
from .voice_client import *
from .webhook import *
from .welcome_screen import *
from .widget import *
Expand Down
60 changes: 60 additions & 0 deletions discord/_voice_aliases.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
"""
The MIT License (MIT)

Copyright (c) 2015-2021 Rapptz
Copyright (c) 2021-present Pycord Development

Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
"""

from typing import TYPE_CHECKING, Any

from typing_extensions import deprecated

if TYPE_CHECKING:
from discord.voice import VoiceClient as VoiceClientC
from discord.voice import VoiceProtocol as VoiceProtocolC

"""
since discord.voice raises an error when importing it without having the
required package (ie davey) installed, we can't import it in __init__ because
that would break the whole library, that is why this file is here.

the error would still be raised, but at least here we have more freedom on how we are typing it
"""

__all__ = ("VoiceProtocol", "VoiceClient")


@deprecated(
"discord.VoiceClient is deprecated in favour of discord.voice.VoiceClient since 2.7 and will be removed in 3.0",
)
def VoiceClient(*args: Any, **kwargs: Any) -> "VoiceClientC":
from discord.voice import VoiceClient as VoiceClientC

return VoiceClientC(*args, **kwargs)


@deprecated(
"discord.VoiceProtocol is deprecated in favour of discord.voice.VoiceProtocol since 2.7 and will be removed in 3.0",
)
def VoiceProtocol(*args: Any, **kwargs: Any) -> "VoiceProtocolC":
from discord.voice import VoiceProtocol as VoiceProtocolC

return VoiceProtocolC(*args, **kwargs)
20 changes: 16 additions & 4 deletions discord/abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@
from .scheduled_events import ScheduledEvent
from .sticker import GuildSticker, StickerItem
from .utils import warn_deprecated
from .voice_client import VoiceClient, VoiceProtocol

__all__ = (
"Snowflake",
Expand All @@ -69,8 +68,6 @@
"Mentionable",
)

T = TypeVar("T", bound=VoiceProtocol)

if TYPE_CHECKING:
from datetime import datetime

Expand Down Expand Up @@ -106,6 +103,10 @@
MessageableChannel = Union[PartialMessageableChannel, GroupChannel]
SnowflakeTime = Union["Snowflake", datetime]

from .voice import VoiceClient, VoiceProtocol

T = TypeVar("T", bound=VoiceProtocol)

MISSING = utils.MISSING


Expand Down Expand Up @@ -2003,6 +2004,7 @@ class Connectable(Protocol):

__slots__ = ()
_state: ConnectionState
id: int

def _get_voice_client_key(self) -> tuple[int, str]:
raise NotImplementedError
Expand All @@ -2015,7 +2017,7 @@ async def connect(
*,
timeout: float = 60.0,
reconnect: bool = True,
cls: Callable[[Client, Connectable], T] = VoiceClient,
cls: Callable[[Client, Connectable], T] = MISSING,
) -> T:
"""|coro|

Expand Down Expand Up @@ -2051,6 +2053,16 @@ async def connect(
The opus library has not been loaded.
"""

# import directly from _types so if the user does not have davey
# it won't error here
from .voice._types import VoiceProtocol

if cls is MISSING:
# if the user passes no cls, then actually import VoiceClient
from .voice import VoiceClient

cls = VoiceClient # pyright: ignore[reportAssignmentType]

key_id, _ = self._get_voice_client_key()
state = self._state

Expand Down
6 changes: 4 additions & 2 deletions discord/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
from .ui.view import BaseView
from .user import ClientUser, User
from .utils import _D, _FETCHABLE, MISSING
from .voice_client import VoiceClient
from .voice import VoiceClient, VoiceProtocol
from .webhook import Webhook
from .widget import Widget

Expand All @@ -87,7 +87,6 @@
from .soundboard import SoundboardSound
from .threads import Thread
from .ui.item import ViewItem
from .voice_client import VoiceProtocol

__all__ = ("Client",)

Expand Down Expand Up @@ -285,6 +284,9 @@ def __init__(
if VoiceClient.warn_nacl:
VoiceClient.warn_nacl = False
_log.warning("PyNaCl is not installed, voice will NOT be supported")
if VoiceClient.warn_davey:
VoiceClient.warn_davey = False
_log.warning("davey is not installed, voice will NOT be supported")

# Used to hard-reference tasks so they don't get garbage collected (discarded with done_callbacks)
self._tasks = set()
Expand Down
2 changes: 1 addition & 1 deletion discord/commands/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
from ..state import ConnectionState
from ..ui import BaseView
from ..user import User
from ..voice_client import VoiceClient
from ..voice import VoiceClient
from ..webhook import WebhookMessage
from .core import ApplicationCommand, Option

Expand Down
2 changes: 1 addition & 1 deletion discord/ext/commands/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
from discord.member import Member
from discord.state import ConnectionState
from discord.user import ClientUser, User
from discord.voice_client import VoiceProtocol
from discord.voice import VoiceProtocol

from .bot import AutoShardedBot, Bot
from .cog import Cog
Expand Down
Loading
Loading