File tree Expand file tree Collapse file tree 2 files changed +51
-0
lines changed Expand file tree Collapse file tree 2 files changed +51
-0
lines changed Original file line number Diff line number Diff line change @@ -1049,6 +1049,56 @@ async def create_invite(
1049
1049
1050
1050
return Invite (** res , _client = self ._client )
1051
1051
1052
+ async def get_history (self , limit : int = 100 ) -> List ["Message" ]: # noqa
1053
+ """
1054
+ Gets messages from the channel's history.
1055
+
1056
+ :param limit?: The amount of messages to get. Default 100
1057
+ :type limit?: int
1058
+ :return: A list of messages
1059
+ :rtype: List[Message]
1060
+ """
1061
+
1062
+ if not self ._client :
1063
+ raise AttributeError ("HTTPClient not found!" )
1064
+
1065
+ from .message import Message
1066
+
1067
+ _messages : List [Message ] = []
1068
+ _before : int = None
1069
+ while limit > 100 :
1070
+ _msgs = [
1071
+ Message (** res , _client = self ._client )
1072
+ for res in await self ._client .get_channel_messages (
1073
+ channel_id = int (self .id ),
1074
+ limit = 100 ,
1075
+ before = _before ,
1076
+ )
1077
+ ]
1078
+ limit -= 100
1079
+ _before = int (_messages [- 1 ].id )
1080
+
1081
+ for msg in _msgs :
1082
+ if msg in _messages :
1083
+ return _messages
1084
+ else :
1085
+ _messages .append (msg )
1086
+
1087
+ if limit > 0 :
1088
+ _msgs = [
1089
+ Message (** res , _client = self ._client )
1090
+ for res in await self ._client .get_channel_messages (
1091
+ channel_id = int (self .id ), limit = limit , before = _before
1092
+ )
1093
+ ]
1094
+ for msg in _msgs :
1095
+ if msg in _messages :
1096
+ return _messages
1097
+ else :
1098
+ _messages .append (msg )
1099
+
1100
+ return _messages
1101
+
1052
1102
1053
1103
class Thread (Channel ):
1054
1104
"""An object representing a thread.
Original file line number Diff line number Diff line change @@ -224,5 +224,6 @@ class Channel(DictSerializerMixin):
224
224
target_user_id : int = MISSING ,
225
225
target_application_id : int = MISSING ,
226
226
) -> Invite : ...
227
+ async def get_history (self , limit : int = 100 ) -> List ["Message" ]: ...
227
228
228
229
class Thread (Channel ): ...
You can’t perform that action at this time.
0 commit comments