Skip to content

Commit 0a652ba

Browse files
committed
feat: add http methods for polls
1 parent decbecf commit 0a652ba

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

interactions/api/http/http_requests/messages.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import discord_typings
44

55
from interactions.models.internal.protocols import CanRequest
6+
from interactions.client.utils.serializer import dict_filter_none
67
from ..route import Route
78

89
__all__ = ("MessageRequests",)
@@ -175,3 +176,59 @@ async def crosspost_message(
175176
)
176177
)
177178
return cast(discord_typings.MessageData, result)
179+
180+
async def get_answer_voters(
181+
self,
182+
channel_id: "Snowflake_Type",
183+
message_id: "Snowflake_Type",
184+
answer_id: int,
185+
after: "Snowflake_Type | None" = None,
186+
limit: int = 25,
187+
) -> list[discord_typings.UserData]:
188+
"""
189+
Get a list of users that voted for this specific answer.
190+
191+
Args:
192+
channel_id: Channel the message is in
193+
message_id: The message with the poll
194+
answer_id: The answer to get voters for
195+
after: Get messages after this user ID
196+
limit: The max number of users to return (default 25, max 100)
197+
198+
Returns:
199+
list[discord_typings.UserData]: A list of users that voted for the answer
200+
201+
"""
202+
result = await self.request(
203+
Route(
204+
"GET",
205+
"/channels/{channel_id}/messages/{message_id}/polls/{answer_id}/votes",
206+
channel_id=channel_id,
207+
message_id=message_id,
208+
answer_id=answer_id,
209+
),
210+
params=dict_filter_none({"after": after, "limit": limit}),
211+
)
212+
return cast(list[discord_typings.UserData], result)
213+
214+
async def end_poll(self, channel_id: "Snowflake_Type", message_id: "Snowflake_Type") -> discord_typings.MessageData:
215+
"""
216+
Ends a poll. Only can end polls from the current bot.
217+
218+
Args:
219+
channel_id: Channel the message is in
220+
message_id: The message with the poll
221+
222+
Returns:
223+
message object
224+
225+
"""
226+
result = await self.request(
227+
Route(
228+
"POST",
229+
"/channels/{channel_id}/messages/{message_id}/polls/end",
230+
channel_id=channel_id,
231+
message_id=message_id,
232+
)
233+
)
234+
return cast(discord_typings.MessageData, result)

0 commit comments

Comments
 (0)