mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-09-05 09:26:10 +00:00
Remove discord.InvalidArgument
This uses TypeError and ValueError instead.
This commit is contained in:
@ -41,7 +41,7 @@ from typing import Any, Dict, List, Literal, Optional, TYPE_CHECKING, Tuple, Typ
|
||||
import weakref
|
||||
|
||||
from .. import utils
|
||||
from ..errors import InvalidArgument, HTTPException, Forbidden, NotFound, DiscordServerError
|
||||
from ..errors import HTTPException, Forbidden, NotFound, DiscordServerError
|
||||
from ..message import Message
|
||||
from ..http import Route, handle_message_parameters
|
||||
from ..channel import PartialMessageable
|
||||
@ -387,6 +387,10 @@ class SyncWebhookMessage(Message):
|
||||
) -> SyncWebhookMessage:
|
||||
"""Edits the message.
|
||||
|
||||
.. versionchanged:: 2.0
|
||||
This function no-longer raises ``InvalidArgument`` instead raising
|
||||
:exc:`ValueError` or :exc:`TypeError` in various cases.
|
||||
|
||||
Parameters
|
||||
------------
|
||||
content: Optional[:class:`str`]
|
||||
@ -418,9 +422,8 @@ class SyncWebhookMessage(Message):
|
||||
TypeError
|
||||
You specified both ``embed`` and ``embeds``
|
||||
ValueError
|
||||
The length of ``embeds`` was invalid
|
||||
InvalidArgument
|
||||
There was no token associated with this webhook.
|
||||
The length of ``embeds`` was invalid or
|
||||
there was no token associated with this webhook.
|
||||
|
||||
Returns
|
||||
--------
|
||||
@ -636,7 +639,7 @@ class SyncWebhook(BaseWebhook):
|
||||
|
||||
Raises
|
||||
-------
|
||||
InvalidArgument
|
||||
ValueError
|
||||
The URL is invalid.
|
||||
|
||||
Returns
|
||||
@ -647,7 +650,7 @@ class SyncWebhook(BaseWebhook):
|
||||
"""
|
||||
m = re.search(r'discord(?:app)?.com/api/webhooks/(?P<id>[0-9]{17,20})/(?P<token>[A-Za-z0-9\.\-\_]{60,68})', url)
|
||||
if m is None:
|
||||
raise InvalidArgument('Invalid webhook URL given.')
|
||||
raise ValueError('Invalid webhook URL given.')
|
||||
|
||||
data: Dict[str, Any] = m.groupdict()
|
||||
data['type'] = 1
|
||||
@ -683,7 +686,7 @@ class SyncWebhook(BaseWebhook):
|
||||
Could not fetch the webhook
|
||||
NotFound
|
||||
Could not find the webhook by this ID
|
||||
InvalidArgument
|
||||
ValueError
|
||||
This webhook does not have a token associated with it.
|
||||
|
||||
Returns
|
||||
@ -698,7 +701,7 @@ class SyncWebhook(BaseWebhook):
|
||||
elif self.token:
|
||||
data = adapter.fetch_webhook_with_token(self.id, self.token, session=self.session)
|
||||
else:
|
||||
raise InvalidArgument('This webhook does not have a token associated with it')
|
||||
raise ValueError('This webhook does not have a token associated with it')
|
||||
|
||||
return SyncWebhook(data, self.session, token=self.auth_token, state=self._state)
|
||||
|
||||
@ -723,11 +726,11 @@ class SyncWebhook(BaseWebhook):
|
||||
This webhook does not exist.
|
||||
Forbidden
|
||||
You do not have permissions to delete this webhook.
|
||||
InvalidArgument
|
||||
ValueError
|
||||
This webhook does not have a token associated with it.
|
||||
"""
|
||||
if self.token is None and self.auth_token is None:
|
||||
raise InvalidArgument('This webhook does not have a token associated with it')
|
||||
raise ValueError('This webhook does not have a token associated with it')
|
||||
|
||||
adapter: WebhookAdapter = _get_webhook_adapter()
|
||||
|
||||
@ -769,7 +772,7 @@ class SyncWebhook(BaseWebhook):
|
||||
Editing the webhook failed.
|
||||
NotFound
|
||||
This webhook does not exist.
|
||||
InvalidArgument
|
||||
ValueError
|
||||
This webhook does not have a token associated with it
|
||||
or it tried editing a channel without authentication.
|
||||
|
||||
@ -779,7 +782,7 @@ class SyncWebhook(BaseWebhook):
|
||||
The newly edited webhook.
|
||||
"""
|
||||
if self.token is None and self.auth_token is None:
|
||||
raise InvalidArgument('This webhook does not have a token associated with it')
|
||||
raise ValueError('This webhook does not have a token associated with it')
|
||||
|
||||
payload = {}
|
||||
if name is not MISSING:
|
||||
@ -794,7 +797,7 @@ class SyncWebhook(BaseWebhook):
|
||||
# If a channel is given, always use the authenticated endpoint
|
||||
if channel is not None:
|
||||
if self.auth_token is None:
|
||||
raise InvalidArgument('Editing channel requires authenticated webhook')
|
||||
raise ValueError('Editing channel requires authenticated webhook')
|
||||
|
||||
payload['channel_id'] = channel.id
|
||||
data = adapter.edit_webhook(self.id, self.auth_token, payload=payload, session=self.session, reason=reason)
|
||||
@ -924,9 +927,8 @@ class SyncWebhook(BaseWebhook):
|
||||
TypeError
|
||||
You specified both ``embed`` and ``embeds`` or ``file`` and ``files``
|
||||
ValueError
|
||||
The length of ``embeds`` was invalid
|
||||
InvalidArgument
|
||||
There was no token associated with this webhook.
|
||||
The length of ``embeds`` was invalid or
|
||||
there was no token associated with this webhook.
|
||||
|
||||
Returns
|
||||
---------
|
||||
@ -935,7 +937,7 @@ class SyncWebhook(BaseWebhook):
|
||||
"""
|
||||
|
||||
if self.token is None:
|
||||
raise InvalidArgument('This webhook does not have a token associated with it')
|
||||
raise ValueError('This webhook does not have a token associated with it')
|
||||
|
||||
previous_mentions: Optional[AllowedMentions] = getattr(self._state, 'allowed_mentions', None)
|
||||
if content is None:
|
||||
@ -989,7 +991,7 @@ class SyncWebhook(BaseWebhook):
|
||||
You do not have the permissions required to get a message.
|
||||
~discord.HTTPException
|
||||
Retrieving the message failed.
|
||||
InvalidArgument
|
||||
ValueError
|
||||
There was no token associated with this webhook.
|
||||
|
||||
Returns
|
||||
@ -999,7 +1001,7 @@ class SyncWebhook(BaseWebhook):
|
||||
"""
|
||||
|
||||
if self.token is None:
|
||||
raise InvalidArgument('This webhook does not have a token associated with it')
|
||||
raise ValueError('This webhook does not have a token associated with it')
|
||||
|
||||
adapter: WebhookAdapter = _get_webhook_adapter()
|
||||
data = adapter.get_webhook_message(
|
||||
@ -1056,13 +1058,12 @@ class SyncWebhook(BaseWebhook):
|
||||
TypeError
|
||||
You specified both ``embed`` and ``embeds``
|
||||
ValueError
|
||||
The length of ``embeds`` was invalid
|
||||
InvalidArgument
|
||||
There was no token associated with this webhook.
|
||||
The length of ``embeds`` was invalid or
|
||||
there was no token associated with this webhook.
|
||||
"""
|
||||
|
||||
if self.token is None:
|
||||
raise InvalidArgument('This webhook does not have a token associated with it')
|
||||
raise ValueError('This webhook does not have a token associated with it')
|
||||
|
||||
previous_mentions: Optional[AllowedMentions] = getattr(self._state, 'allowed_mentions', None)
|
||||
params = handle_message_parameters(
|
||||
@ -1104,9 +1105,11 @@ class SyncWebhook(BaseWebhook):
|
||||
Deleting the message failed.
|
||||
Forbidden
|
||||
Deleted a message that is not yours.
|
||||
ValueError
|
||||
This webhook does not have a token associated with it.
|
||||
"""
|
||||
if self.token is None:
|
||||
raise InvalidArgument('This webhook does not have a token associated with it')
|
||||
raise ValueError('This webhook does not have a token associated with it')
|
||||
|
||||
adapter: WebhookAdapter = _get_webhook_adapter()
|
||||
adapter.delete_webhook_message(
|
||||
|
Reference in New Issue
Block a user