Remove discord.InvalidArgument

This uses TypeError and ValueError instead.
This commit is contained in:
Josh
2022-02-26 16:44:49 +10:00
committed by GitHub
parent 86797dd9ab
commit 2b69b5d545
22 changed files with 342 additions and 176 deletions

View File

@@ -52,7 +52,7 @@ from .emoji import Emoji
from .errors import InvalidData
from .permissions import PermissionOverwrite
from .colour import Colour
from .errors import InvalidArgument, ClientException
from .errors import ClientException
from .channel import *
from .channel import _guild_channel_factory
from .channel import _threaded_guild_channel_factory
@@ -1086,12 +1086,12 @@ class Guild(Hashable):
if overwrites is MISSING:
overwrites = {}
elif not isinstance(overwrites, dict):
raise InvalidArgument('overwrites parameter expects a dict.')
raise TypeError('overwrites parameter expects a dict.')
perms = []
for target, perm in overwrites.items():
if not isinstance(perm, PermissionOverwrite):
raise InvalidArgument(f'Expected PermissionOverwrite received {perm.__class__.__name__}')
raise TypeError(f'Expected PermissionOverwrite received {perm.__class__.__name__}')
allow, deny = perm.pair()
payload = {'allow': allow.value, 'deny': deny.value, 'id': target.id}
@@ -1138,6 +1138,10 @@ class Guild(Hashable):
other channels to follow suit. A follow-up call to :meth:`~TextChannel.edit`
will be required to update the position of the channel in the channel list.
.. versionchanged:: 2.0
This function no-longer raises ``InvalidArgument`` instead raising
:exc:`TypeError`.
Examples
----------
@@ -1189,7 +1193,7 @@ class Guild(Hashable):
You do not have the proper permissions to create this channel.
HTTPException
Creating the channel failed.
InvalidArgument
TypeError
The permission overwrite information is not in proper form.
Returns
@@ -1237,6 +1241,10 @@ class Guild(Hashable):
This is similar to :meth:`create_text_channel` except makes a :class:`VoiceChannel` instead.
.. versionchanged:: 2.0
This function no-longer raises ``InvalidArgument`` instead raising
:exc:`TypeError`.
Parameters
-----------
name: :class:`str`
@@ -1274,7 +1282,7 @@ class Guild(Hashable):
You do not have the proper permissions to create this channel.
HTTPException
Creating the channel failed.
InvalidArgument
TypeError
The permission overwrite information is not in proper form.
Returns
@@ -1323,6 +1331,10 @@ class Guild(Hashable):
.. versionadded:: 1.7
.. versionchanged:: 2.0
This function no-longer raises ``InvalidArgument`` instead raising
:exc:`TypeError`.
Parameters
-----------
name: :class:`str`
@@ -1349,7 +1361,7 @@ class Guild(Hashable):
You do not have the proper permissions to create this channel.
HTTPException
Creating the channel failed.
InvalidArgument
TypeError
The permission overwrite information is not in proper form.
Returns
@@ -1390,13 +1402,17 @@ class Guild(Hashable):
The ``category`` parameter is not supported in this function since categories
cannot have categories.
.. versionchanged:: 2.0
This function no-longer raises ``InvalidArgument`` instead raising
:exc:`TypeError`.
Raises
------
Forbidden
You do not have the proper permissions to create this channel.
HTTPException
Creating the channel failed.
InvalidArgument
TypeError
The permission overwrite information is not in proper form.
Returns
@@ -1495,6 +1511,10 @@ class Guild(Hashable):
.. versionchanged:: 2.0
The ``region`` keyword parameter has been removed.
.. versionchanged:: 2.0
This function no-longer raises ``InvalidArgument`` instead raising
:exc:`ValueError` or :exc:`TypeError` in various cases.
Parameters
----------
name: :class:`str`
@@ -1562,10 +1582,14 @@ class Guild(Hashable):
You do not have permissions to edit the guild.
HTTPException
Editing the guild failed.
InvalidArgument
ValueError
The image format passed in to ``icon`` is invalid. It must be
PNG or JPG. This is also raised if you are not the owner of the
guild and request an ownership transfer.
TypeError
The type passed to the ``default_notifications``, ``verification_level``,
``explicit_content_filter``, or ``system_channel_flags`` parameter was
of the incorrect type.
Returns
--------
@@ -1618,7 +1642,7 @@ class Guild(Hashable):
if default_notifications is not MISSING:
if not isinstance(default_notifications, NotificationLevel):
raise InvalidArgument('default_notifications field must be of type NotificationLevel')
raise TypeError('default_notifications field must be of type NotificationLevel')
fields['default_message_notifications'] = default_notifications.value
if afk_channel is not MISSING:
@@ -1647,25 +1671,25 @@ class Guild(Hashable):
if owner is not MISSING:
if self.owner_id != self._state.self_id:
raise InvalidArgument('To transfer ownership you must be the owner of the guild.')
raise ValueError('To transfer ownership you must be the owner of the guild.')
fields['owner_id'] = owner.id
if verification_level is not MISSING:
if not isinstance(verification_level, VerificationLevel):
raise InvalidArgument('verification_level field must be of type VerificationLevel')
raise TypeError('verification_level field must be of type VerificationLevel')
fields['verification_level'] = verification_level.value
if explicit_content_filter is not MISSING:
if not isinstance(explicit_content_filter, ContentFilter):
raise InvalidArgument('explicit_content_filter field must be of type ContentFilter')
raise TypeError('explicit_content_filter field must be of type ContentFilter')
fields['explicit_content_filter'] = explicit_content_filter.value
if system_channel_flags is not MISSING:
if not isinstance(system_channel_flags, SystemChannelFlags):
raise InvalidArgument('system_channel_flags field must be of type SystemChannelFlags')
raise TypeError('system_channel_flags field must be of type SystemChannelFlags')
fields['system_channel_flags'] = system_channel_flags.value
@@ -1675,7 +1699,7 @@ class Guild(Hashable):
if 'rules_channel_id' in fields and 'public_updates_channel_id' in fields:
features.append('COMMUNITY')
else:
raise InvalidArgument(
raise ValueError(
'community field requires both rules_channel and public_updates_channel fields to be provided'
)
@@ -1982,6 +2006,10 @@ class Guild(Hashable):
.. versionchanged:: 1.4
The ``roles`` keyword-only parameter was added.
.. versionchanged:: 2.0
This function no-longer raises ``InvalidArgument`` instead raising
:exc:`TypeError`.
Parameters
-----------
days: :class:`int`
@@ -2003,7 +2031,7 @@ class Guild(Hashable):
You do not have permissions to prune members.
HTTPException
An error occurred while pruning members.
InvalidArgument
TypeError
An integer was not passed for ``days``.
Returns
@@ -2014,7 +2042,7 @@ class Guild(Hashable):
"""
if not isinstance(days, int):
raise InvalidArgument(f'Expected int for ``days``, received {days.__class__.__name__} instead.')
raise TypeError(f'Expected int for ``days``, received {days.__class__.__name__} instead.')
if roles:
role_ids = [str(role.id) for role in roles]
@@ -2083,6 +2111,10 @@ class Guild(Hashable):
.. versionchanged:: 2.0
The returned value can be ``None``.
.. versionchanged:: 2.0
This function no-longer raises ``InvalidArgument`` instead raising
:exc:`TypeError`.
Parameters
-----------
days: :class:`int`
@@ -2099,7 +2131,7 @@ class Guild(Hashable):
You do not have permissions to prune members.
HTTPException
An error occurred while fetching the prune members estimate.
InvalidArgument
TypeError
An integer was not passed for ``days``.
Returns
@@ -2109,7 +2141,7 @@ class Guild(Hashable):
"""
if not isinstance(days, int):
raise InvalidArgument(f'Expected int for ``days``, received {days.__class__.__name__} instead.')
raise TypeError(f'Expected int for ``days``, received {days.__class__.__name__} instead.')
if roles:
role_ids = [str(role.id) for role in roles]
@@ -2594,6 +2626,10 @@ class Guild(Hashable):
.. versionadded:: 2.0
The ``display_icon`` keyword-only parameter was added.
.. versionchanged:: 2.0
This function no-longer raises ``InvalidArgument`` instead raising
:exc:`TypeError`.
Parameters
-----------
name: :class:`str`
@@ -2623,7 +2659,7 @@ class Guild(Hashable):
You do not have permissions to create the role.
HTTPException
Creating the role failed.
InvalidArgument
TypeError
An invalid keyword argument was given.
Returns
@@ -2674,7 +2710,12 @@ class Guild(Hashable):
.. versionadded:: 1.4
Example:
.. versionchanged:: 2.0
This function no-longer raises ``InvalidArgument`` instead raising
:exc:`TypeError`.
Example
----------
.. code-block:: python3
@@ -2700,7 +2741,7 @@ class Guild(Hashable):
You do not have permissions to move the roles.
HTTPException
Moving the roles failed.
InvalidArgument
TypeError
An invalid keyword argument was given.
Returns
@@ -2709,7 +2750,7 @@ class Guild(Hashable):
A list of all the roles in the guild.
"""
if not isinstance(positions, dict):
raise InvalidArgument('positions parameter expects a dict.')
raise TypeError('positions parameter expects a dict.')
role_positions = []
for role, position in positions.items():