mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-09-06 09:56:09 +00:00
Add support for Polls
Co-authored-by: owocado <24418520+owocado@users.noreply.github.com> Co-authored-by: Josh <8677174+bijij@users.noreply.github.com> Co-authored-by: Trevor Flahardy <75498301+trevorflahardy@users.noreply.github.com>
This commit is contained in:
@ -68,6 +68,7 @@ if TYPE_CHECKING:
|
||||
from .embeds import Embed
|
||||
from .message import Attachment
|
||||
from .flags import MessageFlags
|
||||
from .poll import Poll
|
||||
|
||||
from .types import (
|
||||
appinfo,
|
||||
@ -91,6 +92,7 @@ if TYPE_CHECKING:
|
||||
sticker,
|
||||
welcome_screen,
|
||||
sku,
|
||||
poll,
|
||||
)
|
||||
from .types.snowflake import Snowflake, SnowflakeList
|
||||
|
||||
@ -154,6 +156,7 @@ def handle_message_parameters(
|
||||
thread_name: str = MISSING,
|
||||
channel_payload: Dict[str, Any] = MISSING,
|
||||
applied_tags: Optional[SnowflakeList] = MISSING,
|
||||
poll: Optional[Poll] = MISSING,
|
||||
) -> MultipartParameters:
|
||||
if files is not MISSING and file is not MISSING:
|
||||
raise TypeError('Cannot mix file and files keyword arguments.')
|
||||
@ -256,6 +259,9 @@ def handle_message_parameters(
|
||||
}
|
||||
payload.update(channel_payload)
|
||||
|
||||
if poll not in (MISSING, None):
|
||||
payload['poll'] = poll._to_dict() # type: ignore
|
||||
|
||||
multipart = []
|
||||
if files:
|
||||
multipart.append({'name': 'payload_json', 'value': utils._to_json(payload)})
|
||||
@ -2513,6 +2519,43 @@ class HTTPClient:
|
||||
payload = {k: v for k, v in payload.items() if k in valid_keys}
|
||||
return self.request(Route('PATCH', '/applications/@me'), json=payload, reason=reason)
|
||||
|
||||
def get_poll_answer_voters(
|
||||
self,
|
||||
channel_id: Snowflake,
|
||||
message_id: Snowflake,
|
||||
answer_id: Snowflake,
|
||||
after: Optional[Snowflake] = None,
|
||||
limit: Optional[int] = None,
|
||||
) -> Response[poll.PollAnswerVoters]:
|
||||
params = {}
|
||||
|
||||
if after:
|
||||
params['after'] = int(after)
|
||||
|
||||
if limit is not None:
|
||||
params['limit'] = limit
|
||||
|
||||
return self.request(
|
||||
Route(
|
||||
'GET',
|
||||
'/channels/{channel_id}/polls/{message_id}/answers/{answer_id}',
|
||||
channel_id=channel_id,
|
||||
message_id=message_id,
|
||||
answer_id=answer_id,
|
||||
),
|
||||
params=params,
|
||||
)
|
||||
|
||||
def end_poll(self, channel_id: Snowflake, message_id: Snowflake) -> Response[message.Message]:
|
||||
return self.request(
|
||||
Route(
|
||||
'POST',
|
||||
'/channels/{channel_id}/polls/{message_id}/expire',
|
||||
channel_id=channel_id,
|
||||
message_id=message_id,
|
||||
)
|
||||
)
|
||||
|
||||
async def get_gateway(self, *, encoding: str = 'json', zlib: bool = True) -> str:
|
||||
try:
|
||||
data = await self.request(Route('GET', '/gateway'))
|
||||
|
Reference in New Issue
Block a user