mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-07-01 07:40:07 +00:00
Add webhook creation methods to ForumChannel
This commit is contained in:
parent
0b026b1283
commit
259c6733a3
@ -2285,6 +2285,67 @@ class ForumChannel(discord.abc.GuildChannel, Hashable):
|
|||||||
|
|
||||||
return ThreadWithMessage(thread=thread, message=message)
|
return ThreadWithMessage(thread=thread, message=message)
|
||||||
|
|
||||||
|
async def webhooks(self) -> List[Webhook]:
|
||||||
|
"""|coro|
|
||||||
|
|
||||||
|
Gets the list of webhooks from this channel.
|
||||||
|
|
||||||
|
Requires :attr:`~.Permissions.manage_webhooks` permissions.
|
||||||
|
|
||||||
|
Raises
|
||||||
|
-------
|
||||||
|
Forbidden
|
||||||
|
You don't have permissions to get the webhooks.
|
||||||
|
|
||||||
|
Returns
|
||||||
|
--------
|
||||||
|
List[:class:`Webhook`]
|
||||||
|
The webhooks for this channel.
|
||||||
|
"""
|
||||||
|
|
||||||
|
from .webhook import Webhook
|
||||||
|
|
||||||
|
data = await self._state.http.channel_webhooks(self.id)
|
||||||
|
return [Webhook.from_state(d, state=self._state) for d in data]
|
||||||
|
|
||||||
|
async def create_webhook(self, *, name: str, avatar: Optional[bytes] = None, reason: Optional[str] = None) -> Webhook:
|
||||||
|
"""|coro|
|
||||||
|
|
||||||
|
Creates a webhook for this channel.
|
||||||
|
|
||||||
|
Requires :attr:`~.Permissions.manage_webhooks` permissions.
|
||||||
|
|
||||||
|
Parameters
|
||||||
|
-------------
|
||||||
|
name: :class:`str`
|
||||||
|
The webhook's name.
|
||||||
|
avatar: Optional[:class:`bytes`]
|
||||||
|
A :term:`py:bytes-like object` representing the webhook's default avatar.
|
||||||
|
This operates similarly to :meth:`~ClientUser.edit`.
|
||||||
|
reason: Optional[:class:`str`]
|
||||||
|
The reason for creating this webhook. Shows up in the audit logs.
|
||||||
|
|
||||||
|
Raises
|
||||||
|
-------
|
||||||
|
HTTPException
|
||||||
|
Creating the webhook failed.
|
||||||
|
Forbidden
|
||||||
|
You do not have permissions to create a webhook.
|
||||||
|
|
||||||
|
Returns
|
||||||
|
--------
|
||||||
|
:class:`Webhook`
|
||||||
|
The created webhook.
|
||||||
|
"""
|
||||||
|
|
||||||
|
from .webhook import Webhook
|
||||||
|
|
||||||
|
if avatar is not None:
|
||||||
|
avatar = utils._bytes_to_base64_data(avatar) # type: ignore # Silence reassignment error
|
||||||
|
|
||||||
|
data = await self._state.http.create_webhook(self.id, name=str(name), avatar=avatar, reason=reason)
|
||||||
|
return Webhook.from_state(data, state=self._state)
|
||||||
|
|
||||||
|
|
||||||
class DMChannel(discord.abc.Messageable, Hashable):
|
class DMChannel(discord.abc.Messageable, Hashable):
|
||||||
"""Represents a Discord direct message channel.
|
"""Represents a Discord direct message channel.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user