Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

5.14 #1744

Open
wants to merge 4 commits into
base: stable
Choose a base branch
from
Open

5.14 #1744

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
6 changes: 5 additions & 1 deletion interactions/api/http/http_requests/webhooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ async def execute_webhook(
payload: dict,
wait: bool = False,
thread_id: "Snowflake_Type" = None,
thread_name: Optional[str] = None,
files: list["UPLOADABLE_TYPE"] | None = None,
) -> Optional[discord_typings.MessageData]:
"""
Expand All @@ -136,13 +137,16 @@ async def execute_webhook(
webhook_token: The token for the webhook
payload: The JSON payload for the message
wait: Waits for server confirmation of message send before response
thread_id: Send a message to the specified thread
thread_id: Send a message to the specified thread. Note that this cannot be used with `thread_name`
thread_name: Create a thread with this name. Note that this is only valid for forum channel and cannot be used with `thread_id`
files: The files to send with this message

Returns:
The sent `message`, if `wait` is True else None

"""
if thread_name is not None:
payload["thread_name"] = thread_name
return await self.request(
Route("POST", "/webhooks/{webhook_id}/{webhook_token}", webhook_id=webhook_id, webhook_token=webhook_token),
params=dict_filter_none({"wait": "true" if wait else "false", "thread_id": thread_id}),
Expand Down
2 changes: 1 addition & 1 deletion interactions/models/discord/channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -2399,7 +2399,7 @@ async def close_stage(self, reason: Absent[Optional[str]] = MISSING) -> None:


@attrs.define(eq=False, order=False, hash=False, kw_only=True)
class GuildForum(GuildChannel, InvitableMixin):
class GuildForum(GuildChannel, InvitableMixin, WebhookMixin):
available_tags: List[ThreadTag] = attrs.field(repr=False, factory=list)
"""A list of tags available to assign to threads"""
default_reaction_emoji: Optional[DefaultReaction] = attrs.field(repr=False, default=None)
Expand Down
2 changes: 2 additions & 0 deletions interactions/models/discord/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,7 @@ class MessageType(CursedIntEnum):
GUILD_INCIDENT_REPORT_RAID = 38
GUILD_INCIDENT_REPORT_FALSE_ALARM = 39
PURCHASE_NOTIFICATION = 44
POLL_RESULT = 46

@classmethod
def deletable(cls) -> Tuple["MessageType", ...]:
Expand Down Expand Up @@ -434,6 +435,7 @@ def deletable(cls) -> Tuple["MessageType", ...]:
cls.GUILD_INCIDENT_REPORT_RAID,
cls.GUILD_INCIDENT_REPORT_FALSE_ALARM,
cls.PURCHASE_NOTIFICATION,
cls.POLL_RESULT,
)


Expand Down
10 changes: 9 additions & 1 deletion interactions/models/discord/webhooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ async def send(
avatar_url: str | None = None,
wait: bool = False,
thread: "Snowflake_Type" = None,
thread_name: Optional[str] = None,
**kwargs,
) -> Optional["Message"]:
"""
Expand All @@ -218,7 +219,8 @@ async def send(
username: The username to use
avatar_url: The url of an image to use as the avatar
wait: Waits for confirmation of delivery. Set this to True if you intend to edit the message
thread: Send this webhook to a thread channel
thread: Send this webhook to a thread channel. Note that this cannot be used with `thread_name` set
thread_name: Create a thread with `thread_name` with this webhook. Note that this is only valid for forum channel and cannot be used with `thread` set

Returns:
New message object that was sent if `wait` is set to True
Expand All @@ -230,6 +232,11 @@ async def send(
if not content and not embeds and not embed and not files and not file and not stickers:
raise EmptyMessageException("You cannot send a message without any content, embeds, files, or stickers")

if thread is not None and thread_name is not None:
raise ValueError(
"You cannot create a thread and send the message to another thread with a webhook at the same time!"
)

if suppress_embeds:
if isinstance(flags, int):
flags = MessageFlags(flags)
Expand All @@ -256,6 +263,7 @@ async def send(
message_payload,
wait,
to_optional_snowflake(thread),
thread_name,
files=files or file,
)
if message_data:
Expand Down
Loading