Skip to content
Merged
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
18 changes: 17 additions & 1 deletion interactions/api/gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@

log = get_logger("gateway")


__all__ = ("_Heartbeat", "WebSocketClient")


Expand Down Expand Up @@ -621,3 +620,20 @@ def shard(self) -> Optional[List[Tuple[int]]]:
def presence(self) -> Optional[ClientPresence]:
"""Returns the current presence."""
return self.__presence

async def _update_presence(self, presence: ClientPresence) -> None:
"""
Sends an ``UPDATE_PRESENCE`` packet to the gateway.

.. note::
There is a ratelimit to using this method (5 per minute).
As there's no gateway ratelimiter yet, breaking this ratelimit
will force your bot to disconnect.

:param presence: The presence to change the bot to on identify.
:type presence: ClientPresence
"""
payload: dict = {"op": OpCodeType.PRESENCE, "d": presence._json}
await self._send_packet(payload)
log.debug(f"UPDATE_PRESENCE: {presence._json}")
self.__presence = presence
1 change: 1 addition & 0 deletions interactions/api/gateway.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,4 @@ class WebSocketClient:
@property
def presence(self) -> None: ...
async def restart(self): ...
async def _update_presence(self, presence: ClientPresence) -> None: ...
15 changes: 15 additions & 0 deletions interactions/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from .api.models.flags import Intents
from .api.models.guild import Guild
from .api.models.misc import MISSING, Snowflake
from .api.models.presence import ClientPresence
from .api.models.team import Application
from .base import get_logger
from .decor import command
Expand Down Expand Up @@ -330,6 +331,20 @@ def event(self, coro: Coroutine, name: Optional[str] = MISSING) -> Callable[...,
self._websocket._dispatch.register(coro, name if name is not MISSING else coro.__name__)
return coro

async def change_presence(self, presence: ClientPresence) -> None:
"""
A method that changes the current client's presence on runtime.

.. note::
There is a ratelimit to using this method (5 per minute).
As there's no gateway ratelimiter yet, breaking this ratelimit
will force your bot to disconnect.

:param presence: The presence to change the bot to on identify.
:type presence: ClientPresence
"""
await self._websocket._update_presence(presence)

def __check_command(
self,
command: ApplicationCommand,
Expand Down
1 change: 1 addition & 0 deletions interactions/client.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class Client:
async def _login(self) -> None: ...
async def wait_until_ready(self) -> None: ...
def event(self, coro: Coroutine, name: Optional[str] = None) -> Callable[..., Any]: ...
def change_presence(self, presence: ClientPresence) -> None: ...
def __check_command(
self,
command: ApplicationCommand,
Expand Down
2 changes: 1 addition & 1 deletion interactions/models/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from ..api.error import InteractionException
from ..api.models.message import Emoji
from ..api.models.misc import MISSING, DictSerializerMixin
from ..api.models.misc import DictSerializerMixin
from ..enums import ButtonStyle, ComponentType, TextStyleType


Expand Down