Skip to content

Commit fc366c7

Browse files
committed
Add new message search params
1 parent f0700e0 commit fc366c7

File tree

2 files changed

+53
-13
lines changed

2 files changed

+53
-13
lines changed

discord/abc.py

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,8 @@ async def _handle_message_search(
268268
after: SnowflakeTime = MISSING,
269269
include_nsfw: bool = MISSING,
270270
content: str = MISSING,
271+
contents: Sequence[str] = MISSING,
272+
slop: int = 0,
271273
channels: Collection[Snowflake] = MISSING,
272274
authors: Collection[Snowflake] = MISSING,
273275
author_types: Collection[MessageSearchAuthorType] = MISSING,
@@ -280,7 +282,8 @@ async def _handle_message_search(
280282
link_hostnames: Collection[str] = MISSING,
281283
attachment_filenames: Collection[str] = MISSING,
282284
attachment_extensions: Collection[str] = MISSING,
283-
application_commands: Collection[Snowflake] = MISSING,
285+
application_command_id: Optional[Snowflake] = MISSING,
286+
application_command_name: Optional[str] = MISSING,
284287
oldest_first: bool = MISSING,
285288
most_relevant: bool = False,
286289
) -> AsyncIterator[Message]:
@@ -295,6 +298,11 @@ async def _handle_message_search(
295298
if offset < 0:
296299
raise ValueError('offset must be greater than or equal to 0')
297300

301+
if application_command_id and not application_command_name:
302+
raise TypeError('application_command_name must be specified if application_command_id is specified')
303+
if application_command_name and not application_command_id:
304+
raise TypeError('application_command_id must be specified if application_command_name is specified')
305+
298306
_channels = {c.id: c for c in channels} if channels else {}
299307

300308
# Guild channels must go through the guild search endpoint
@@ -350,6 +358,10 @@ def _resolve_channel(message: PartialMessagePayload, /):
350358
payload['include_nsfw'] = str(include_nsfw).lower()
351359
if content:
352360
payload['content'] = content
361+
if contents:
362+
payload['contents'] = list(contents)
363+
if slop:
364+
payload['slop'] = slop
353365
if channels:
354366
payload['channel_id'] = [c.id for c in channels]
355367
if authors:
@@ -374,8 +386,10 @@ def _resolve_channel(message: PartialMessagePayload, /):
374386
payload['attachment_filename'] = list(attachment_filenames)
375387
if attachment_extensions:
376388
payload['attachment_extension'] = list(attachment_extensions)
377-
if application_commands:
378-
payload['command_id'] = [c.id for c in application_commands]
389+
if application_command_id:
390+
payload['command_id'] = application_command_id.id
391+
if application_command_name:
392+
payload['command_name'] = application_command_name
379393
if oldest_first:
380394
payload['sort_order'] = 'asc'
381395
if most_relevant:
@@ -2401,6 +2415,8 @@ def search(
24012415
self,
24022416
content: str = MISSING,
24032417
*,
2418+
contents: Sequence[str] = MISSING,
2419+
slop: int = MISSING,
24042420
limit: Optional[int] = 25,
24052421
offset: int = 0,
24062422
before: SnowflakeTime = MISSING,
@@ -2416,7 +2432,8 @@ def search(
24162432
link_hostnames: Collection[str] = MISSING,
24172433
attachment_filenames: Collection[str] = MISSING,
24182434
attachment_extensions: Collection[str] = MISSING,
2419-
application_commands: Collection[Snowflake] = MISSING,
2435+
application_command_id: Snowflake = MISSING,
2436+
application_command_name: str = MISSING,
24202437
oldest_first: bool = MISSING,
24212438
most_relevant: bool = False,
24222439
) -> AsyncIterator[Message]:
@@ -2453,6 +2470,10 @@ def search(
24532470
-----------
24542471
content: :class:`str`
24552472
The message content to search for.
2473+
contents: List[:class:`str`]
2474+
Tokenized message contents to search for. Must be prefixed with ``0|`` for exact match or ``2|`` for fuzzy match.
2475+
slop: :class:`int`
2476+
The slop for message content token matching from 0 to 100. Defaults to 2.
24562477
limit: Optional[:class:`int`]
24572478
The number of messages to retrieve.
24582479
If ``None``, retrieves every message in the results. Note, however,
@@ -2492,13 +2513,15 @@ def search(
24922513
The attachment filenames to filter by.
24932514
attachment_extensions: List[:class:`str`]
24942515
The attachment extensions to filter by (e.g. txt).
2495-
application_commands: List[:class:`~discord.abc.ApplicationCommand`]
2496-
The used application commands to filter by.
2516+
application_command_id: :class:`int`
2517+
The application command ID to filter by. Must be used with ``application_command_name``.
2518+
application_command_name: :class:`str`
2519+
The application command name to filter by. Must be used with ``application_command_id``.
24972520
oldest_first: :class:`bool`
24982521
Whether to return the oldest results first. Defaults to ``True`` if
24992522
``after`` is specified, otherwise ``False``. Ignored when ``most_relevant`` is set.
25002523
most_relevant: :class:`bool`
2501-
Whether to sort the results by relevance. Limits pagination to 9975 entries.
2524+
Whether to sort the results by relevance. Limits pagination to 10,000 entries.
25022525
25032526
Raises
25042527
------
@@ -2508,6 +2531,7 @@ def search(
25082531
Provided both ``before`` and ``after`` when ``most_relevant`` is set.
25092532
ValueError
25102533
Could not resolve the channel's guild ID.
2534+
Did not provide both ``application_command_id`` and ``application_command_name``.
25112535
25122536
Yields
25132537
-------
@@ -2521,6 +2545,8 @@ def search(
25212545
before=before,
25222546
after=after,
25232547
content=content,
2548+
contents=contents,
2549+
slop=slop,
25242550
authors=authors,
25252551
author_types=author_types,
25262552
mentions=mentions,
@@ -2532,7 +2558,8 @@ def search(
25322558
link_hostnames=link_hostnames,
25332559
attachment_filenames=attachment_filenames,
25342560
attachment_extensions=attachment_extensions,
2535-
application_commands=application_commands,
2561+
application_command_id=application_command_id,
2562+
application_command_name=application_command_name,
25362563
oldest_first=oldest_first,
25372564
most_relevant=most_relevant,
25382565
)

discord/guild.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2953,6 +2953,8 @@ def search(
29532953
self,
29542954
content: str = MISSING,
29552955
*,
2956+
contents: Sequence[str] = MISSING,
2957+
slop: int = MISSING,
29562958
limit: Optional[int] = 25,
29572959
offset: int = 0,
29582960
before: SnowflakeTime = MISSING,
@@ -2970,7 +2972,8 @@ def search(
29702972
link_hostnames: Collection[str] = MISSING,
29712973
attachment_filenames: Collection[str] = MISSING,
29722974
attachment_extensions: Collection[str] = MISSING,
2973-
application_commands: Collection[Snowflake] = MISSING,
2975+
application_command_id: Snowflake = MISSING,
2976+
application_command_name: str = MISSING,
29742977
oldest_first: bool = MISSING,
29752978
most_relevant: bool = False,
29762979
) -> AsyncIterator[Message]:
@@ -3007,6 +3010,10 @@ def search(
30073010
-----------
30083011
content: :class:`str`
30093012
The message content to search for.
3013+
contents: List[:class:`str`]
3014+
Tokenized message contents to search for. Must be prefixed with ``0|`` for exact match or ``2|`` for fuzzy match.
3015+
slop: :class:`int`
3016+
The slop for message content token matching from 0 to 100. Defaults to 2.
30103017
limit: Optional[:class:`int`]
30113018
The number of messages to retrieve.
30123019
If ``None``, retrieves every message in the results. Note, however,
@@ -3050,20 +3057,23 @@ def search(
30503057
The attachment filenames to filter by.
30513058
attachment_extensions: List[:class:`str`]
30523059
The attachment extensions to filter by (e.g. txt).
3053-
application_commands: List[:class:`abc.ApplicationCommand`]
3054-
The used application commands to filter by.
3060+
application_command_id: :class:`int`
3061+
The used application command ID to filter by.
3062+
application_command_name: :class:`str`
3063+
The used application command name to filter by.
30553064
oldest_first: :class:`bool`
30563065
Whether to return the oldest results first. Defaults to ``True`` if
30573066
``before`` is specified, otherwise ``False``. Ignored when ``most_relevant`` is set.
30583067
most_relevant: :class:`bool`
3059-
Whether to sort the results by relevance. Limits pagination to 9975 entries.
3068+
Whether to sort the results by relevance. Limits pagination to 10,000 entries.
30603069
30613070
Raises
30623071
------
30633072
~discord.HTTPException
30643073
The request to search messages failed.
30653074
TypeError
30663075
Provided both ``before`` and ``after`` when ``most_relevant`` is set.
3076+
Did not provide both ``application_command_id`` and ``application_command_name``.
30673077
ValueError
30683078
Could not resolve the channel's guild ID.
30693079
@@ -3079,6 +3089,8 @@ def search(
30793089
before=before,
30803090
after=after,
30813091
content=content,
3092+
contents=contents,
3093+
slop=slop,
30823094
include_nsfw=include_nsfw,
30833095
channels=channels,
30843096
authors=authors,
@@ -3092,7 +3104,8 @@ def search(
30923104
link_hostnames=link_hostnames,
30933105
attachment_filenames=attachment_filenames,
30943106
attachment_extensions=attachment_extensions,
3095-
application_commands=application_commands,
3107+
application_command_id=application_command_id,
3108+
application_command_name=application_command_name,
30963109
oldest_first=oldest_first,
30973110
most_relevant=most_relevant,
30983111
)

0 commit comments

Comments
 (0)