@@ -16,22 +16,27 @@ class Thread(ThreadABC):
16
16
"""Represents a discord Modmail thread"""
17
17
18
18
def __init__ (self , manager : 'ThreadManager' ,
19
- recipient : typing .Union [discord .Member , discord .User ],
19
+ recipient : typing .Union [discord .Member , discord .User ,
20
+ int ],
20
21
channel : typing .Union [discord .DMChannel ,
21
22
discord .TextChannel ]):
22
23
if recipient .bot :
23
24
raise CommandError ('Recipient cannot be a bot.' )
24
25
25
26
self .manager = manager
26
27
self .bot = manager .bot
27
- self ._id = recipient .id
28
- self ._recipient = recipient
28
+ if isinstance (recipient , int ):
29
+ self ._id = recipient
30
+ self ._recipient = None
31
+ else :
32
+ self ._id = recipient .id
33
+ self ._recipient = recipient
29
34
self ._channel = channel
30
35
self ._ready_event = asyncio .Event ()
31
36
self ._close_task = None
32
37
33
38
def __repr__ (self ):
34
- return (f'Thread(recipient="{ self .recipient } ", '
39
+ return (f'Thread(recipient="{ self .recipient or self . id } ", '
35
40
f'channel={ self .channel .id } )' )
36
41
37
42
async def wait_until_ready (self ):
@@ -134,7 +139,10 @@ async def _close(self, closer, silent=False, delete_channel=True,
134
139
else :
135
140
log_url = f"https://logs.modmail.tk/{ log_data ['key' ]} "
136
141
137
- user = self .recipient .mention if self .recipient else f'`{ self .id } `'
142
+ if self .recipient is not None :
143
+ user = self .recipient .mention
144
+ else :
145
+ user = f'`{ self .id } `'
138
146
139
147
if log_data ['messages' ]:
140
148
msg = str (log_data ['messages' ][0 ]['content' ])
@@ -497,9 +505,9 @@ async def _find_from_channel(self, channel):
497
505
498
506
recipient = self .bot .get_user (user_id ) # this could be None
499
507
if recipient is None :
500
- raise ValueError ( 'Recipient not found.' )
501
-
502
- self .cache [user_id ] = thread = Thread (self , recipient , channel )
508
+ self . cache [ user_id ] = thread = Thread ( self , user_id , channel )
509
+ else :
510
+ self .cache [user_id ] = thread = Thread (self , recipient , channel )
503
511
thread .ready = True
504
512
505
513
return thread
0 commit comments