@@ -282,13 +282,15 @@ async def accept_solution(self, interaction: Interaction, message: Message) -> N
282282 thread = interaction .channel
283283 is_thread = isinstance (thread , Thread )
284284 thread_id = thread .id if is_thread else None
285+ thread_author_id = thread .owner_id if is_thread else None
285286 message_id = message .id
286287 forum = thread .parent if is_thread else None
287288 staff_roles : list [int ] = self .bot .config .guild .staff_roles # type: ignore
288- user_id = interaction . user .id
289+ user_id = message . author .id
289290
290291 if (
291292 not is_thread
293+ or not thread_author_id
292294 or not thread_id
293295 or not forum
294296 or not isinstance (forum , ForumChannel )
@@ -297,9 +299,14 @@ async def accept_solution(self, interaction: Interaction, message: Message) -> N
297299 "This command can only be used in threads." , ephemeral = True
298300 )
299301
300- if interaction . user != message . author :
302+ if thread . archived :
301303 return await interaction .response .send_message (
302- "Only the thread author can mark solutions." , ephemeral = True
304+ "This thread is archived." , ephemeral = True
305+ )
306+
307+ if message .author .bot :
308+ return await interaction .response .send_message (
309+ "Cannot mark a bot's post as a solution." , ephemeral = True
303310 )
304311
305312 if message_id == thread_id :
@@ -328,20 +335,32 @@ async def accept_solution(self, interaction: Interaction, message: Message) -> N
328335 return
329336
330337 current_solution = await self .db .get_accepted_solution (thread_id )
338+
331339 if current_solution :
332340 old_message = await thread .fetch_message (current_solution .message_id )
333- await old_message .remove_reaction ("✅" , interaction .user )
334341 await old_message .unpin ()
342+ if self .bot .user :
343+ await old_message .remove_reaction ("✅" , self .bot .user )
335344
336345 await message .add_reaction ("✅" )
337346 await message .pin ()
338- await self .db .mark_as_solution (
339- post_assist_config_id , thread_id , message .id , user_id
340- )
347+
348+ if current_solution :
349+ await self .db .update_user_mark_as_solution (
350+ post_assist_config_id ,
351+ thread_id ,
352+ message_id ,
353+ current_solution .user_id ,
354+ user_id ,
355+ )
356+ else :
357+ await self .db .mark_as_solution (
358+ post_assist_config_id , thread_id , message_id , user_id
359+ )
341360
342361 mark_as_solved_button = PersistentSolverView (
343- thread . id ,
344- thread . owner_id ,
362+ thread_id ,
363+ thread_author_id ,
345364 self .dev_help_views_db ,
346365 self .dev_help_tag_db ,
347366 forum ,
0 commit comments