Add reason to TextChannel.create_webhook
The reason parameter does not work with webhook deletes or edits so they're not added. Probably a Discord bug.
This commit is contained in:
parent
f5c38c3559
commit
eb4de55f6d
@ -403,13 +403,16 @@ class TextChannel(discord.abc.Messageable, discord.abc.GuildChannel, Hashable):
|
|||||||
data = await self._state.http.channel_webhooks(self.id)
|
data = await self._state.http.channel_webhooks(self.id)
|
||||||
return [Webhook.from_state(d, state=self._state) for d in data]
|
return [Webhook.from_state(d, state=self._state) for d in data]
|
||||||
|
|
||||||
async def create_webhook(self, *, name, avatar=None):
|
async def create_webhook(self, *, name, avatar=None, reason=None):
|
||||||
"""|coro|
|
"""|coro|
|
||||||
|
|
||||||
Creates a webhook for this channel.
|
Creates a webhook for this channel.
|
||||||
|
|
||||||
Requires :attr:`~.Permissions.manage_webhooks` permissions.
|
Requires :attr:`~.Permissions.manage_webhooks` permissions.
|
||||||
|
|
||||||
|
.. versionchanged:: 1.1.0
|
||||||
|
Added the ``reason`` keyword-only parameter.
|
||||||
|
|
||||||
Parameters
|
Parameters
|
||||||
-------------
|
-------------
|
||||||
name: :class:`str`
|
name: :class:`str`
|
||||||
@ -417,6 +420,8 @@ class TextChannel(discord.abc.Messageable, discord.abc.GuildChannel, Hashable):
|
|||||||
avatar: Optional[:class:`bytes`]
|
avatar: Optional[:class:`bytes`]
|
||||||
A :term:`py:bytes-like object` representing the webhook's default avatar.
|
A :term:`py:bytes-like object` representing the webhook's default avatar.
|
||||||
This operates similarly to :meth:`~ClientUser.edit`.
|
This operates similarly to :meth:`~ClientUser.edit`.
|
||||||
|
reason: Optional[:class:`str`]
|
||||||
|
The reason for creating this webhook. Shows up in the audit logs.
|
||||||
|
|
||||||
Raises
|
Raises
|
||||||
-------
|
-------
|
||||||
@ -434,7 +439,7 @@ class TextChannel(discord.abc.Messageable, discord.abc.GuildChannel, Hashable):
|
|||||||
if avatar is not None:
|
if avatar is not None:
|
||||||
avatar = utils._bytes_to_base64_data(avatar)
|
avatar = utils._bytes_to_base64_data(avatar)
|
||||||
|
|
||||||
data = await self._state.http.create_webhook(self.id, name=str(name), avatar=avatar)
|
data = await self._state.http.create_webhook(self.id, name=str(name), avatar=avatar, reason=reason)
|
||||||
return Webhook.from_state(data, state=self._state)
|
return Webhook.from_state(data, state=self._state)
|
||||||
|
|
||||||
class VoiceChannel(discord.abc.Connectable, discord.abc.GuildChannel, Hashable):
|
class VoiceChannel(discord.abc.Connectable, discord.abc.GuildChannel, Hashable):
|
||||||
|
@ -537,14 +537,15 @@ class HTTPClient:
|
|||||||
|
|
||||||
# Webhook management
|
# Webhook management
|
||||||
|
|
||||||
def create_webhook(self, channel_id, *, name, avatar=None):
|
def create_webhook(self, channel_id, *, name, avatar=None, reason=None):
|
||||||
payload = {
|
payload = {
|
||||||
'name': name
|
'name': name
|
||||||
}
|
}
|
||||||
if avatar is not None:
|
if avatar is not None:
|
||||||
payload['avatar'] = avatar
|
payload['avatar'] = avatar
|
||||||
|
|
||||||
return self.request(Route('POST', '/channels/{channel_id}/webhooks', channel_id=channel_id), json=payload)
|
r = Route('POST', '/channels/{channel_id}/webhooks', channel_id=channel_id)
|
||||||
|
return self.request(r, json=payload, reason=reason)
|
||||||
|
|
||||||
def channel_webhooks(self, channel_id):
|
def channel_webhooks(self, channel_id):
|
||||||
return self.request(Route('GET', '/channels/{channel_id}/webhooks', channel_id=channel_id))
|
return self.request(Route('GET', '/channels/{channel_id}/webhooks', channel_id=channel_id))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user