Skip to content

Commit fbdccbb

Browse files
committed
Add a timeout_for method
1 parent ca1a76c commit fbdccbb

File tree

1 file changed

+32
-10
lines changed

1 file changed

+32
-10
lines changed

discord/member.py

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,17 @@
3030
import itertools
3131
import sys
3232
from operator import attrgetter
33-
from typing import Any, Dict, List, Literal, Optional, TYPE_CHECKING, Tuple, Type, TypeVar, Union, overload
33+
from typing import Any, Dict, List, Literal, Optional, TYPE_CHECKING, Tuple, Type, TypeVar, Union
3434

3535
import discord.abc
36-
3736
from . import utils
38-
from .asset import Asset
39-
from .utils import MISSING
40-
from .user import BaseUser, User, _UserTag
4137
from .activity import create_activity, ActivityTypes
42-
from .permissions import Permissions
43-
from .enums import Status, try_enum
4438
from .colour import Colour
39+
from .enums import Status, try_enum
4540
from .object import Object
41+
from .permissions import Permissions
42+
from .user import BaseUser, User, _UserTag
43+
from .utils import MISSING
4644

4745
__all__ = (
4846
'VoiceState',
@@ -788,10 +786,9 @@ async def edit(
788786
async def timeout(self, until: Optional[datetime.datetime], *, reason: Optional[str] = None) -> None:
789787
"""|coro|
790788
791-
Timeouts a member from the guild for the set duration.
789+
Applies a timeout to a member in the guild until a set datetime.
792790
793-
You must have the :attr:`~Permissions.moderate_members` permission to
794-
timeout a member.
791+
You must have the :attr:`~Permissions.moderate_members` permission to timeout a member.
795792
796793
Parameters
797794
-----------
@@ -809,6 +806,31 @@ async def timeout(self, until: Optional[datetime.datetime], *, reason: Optional[
809806
"""
810807
await self.edit(communication_disabled_until=until, reason=reason)
811808

809+
async def timeout_for(self, duration: datetime.timedelta, *, reason: Optional[str] = None) -> None:
810+
"""|coro|
811+
812+
Applies a timeout to a member in the guild for a set duration. A shortcut method for :meth:`~.timeout`, and
813+
equivalent to ``timeout(until=datetime.utcnow() + duration, reason=reason)``.
814+
815+
You must have the :attr:`~Permissions.moderate_members` permission to
816+
timeout a member.
817+
818+
Parameters
819+
-----------
820+
duration: :class:`datetime.timedelta`
821+
The duration to timeout the member for.
822+
reason: Optional[:class:`str`]
823+
The reason for doing this action. Shows up on the audit log.
824+
825+
Raises
826+
-------
827+
Forbidden
828+
You do not have permissions to timeout members.
829+
HTTPException
830+
An error occurred doing the request.
831+
"""
832+
await self.timeout(datetime.datetime.now(datetime.timezone.utc) + duration, reason=reason)
833+
812834
async def remove_timeout(self, *, reason: Optional[str] = None) -> None:
813835
"""|coro|
814836

0 commit comments

Comments
 (0)