feat: cache voice channel info from gateway#3210
Conversation
|
Thanks for opening this pull request! This pull request can be checked-out with: git fetch origin pull/3210/head:pr-3210
git checkout pr-3210This pull request can be installed with: pip install git+https://github.com/Pycord-Development/pycord@refs/pull/3210/head |
…o feat/channel-status-gateway # Conflicts: # discord/channel.py
|
Test code I've been using: import asyncio
import discord
import logging
logging.basicConfig(level=logging.DEBUG)
client = discord.Client(cache_channel_info=True, intents=discord.Intents.all(), chunk_guilds_at_startup=False)
@client.event
async def on_ready():
while True:
for channel in client.get_all_channels():
if hasattr(channel, "voice_start_time") and channel.voice_start_time:
print("rec", getattr(channel, "status", ...), channel.voice_start_time)
@client.event
async def on_voice_channel_status_update(channel, old, new):
print("status", channel.status, channel.voice_start_time, old, new)
@client.event
async def on_voice_channel_start_time_update(channel, old, new):
print("start", channel.status, channel.voice_start_time, old, new)
client.run("token") |
…o feat/channel-status-gateway
|
Needs input: API for |
…o feat/channel-status-gateway
|
|
||
| .. versionadded:: 2.8 | ||
| cache_channel_info: :class:`bool` | ||
| Whether to automatically request and cache channel statuses on startup. Defaults to ``False``. |
There was a problem hiding this comment.
| Whether to automatically request and cache channel statuses on startup. Defaults to ``False``. | |
| Whether to automatically request and cache voice channel statuses on startup. Defaults to ``False``. |
| if not self._state.is_guild_evicted(self): | ||
| return await self._state.chunk_guild(self, cache=cache) | ||
|
|
||
| async def channel_info(self, *, cache: bool = True) -> None | list[ChannelInfo]: |
There was a problem hiding this comment.
I don't really like async methods that have attribute-like names. We have many in the lib already but I don't think we should create new ones when we have the opportunity to. I think you mentioned something about this naming as well (?)
Some ideas:
request_channel_infofetch_channel_info
| Raises | ||
| ------ | ||
| ClientException | ||
| The members intent is not enabled. |
There was a problem hiding this comment.
Maybe have a "this requires the members intent" notice in the main docstring body similar to how it's done in other places
| The guild ID where the voice channel start time update originated from. | ||
| voice_start_time: Optional[:class:`datetime.datetime`] | ||
| The new new voice channel start time. | ||
| data: :class:`dict` |
There was a problem hiding this comment.
Do we want to document this ?
| self._get_guild, | ||
| cache=cache, | ||
| ) | ||
| ws = self._get_websocket(guild.id) # This is ignored upstream |
Caution
Feature freeze is active, as described by our Release Schedule.
Summary
https://docs.discord.com/developers/change-log#voice-channel-status-and-start-time-documentation
cache_channel_info, defaultFalse)voice_channel_start_time_updateeventvoice_start_timeto voice channels.statusis stored on voice channels.Information
examples, ...).
Checklist
type: ignorecomments were used, a comment is also left explaining why.