@@ -56,7 +56,7 @@ def __init__(self, DISCORD_BOT_TOKEN: Optional[str] = None,
5656 def _to_int (val : Optional [Union [str , int ]]) -> Optional [int ]:
5757 try :
5858 return int (val ) if val is not None and str (val ).strip () else None
59- except Exception :
59+ except ValueError :
6060 return None
6161
6262 def _register_events (self ):
@@ -96,8 +96,8 @@ async def on_interaction(interaction: discord.Interaction):
9696 return
9797 try :
9898 await interaction .response .defer (ephemeral = True )
99- except Exception :
100- pass
99+ except Exception as e :
100+ logger . error ( f"处理 Discord 交互响应失败: { e } " )
101101
102102 username = (interaction .user .display_name or interaction .user .global_name or interaction .user .name ) \
103103 if interaction .user else None
@@ -126,8 +126,8 @@ def runner():
126126 finally :
127127 try :
128128 self ._loop .run_until_complete (self ._client .close ())
129- except Exception :
130- pass
129+ except Exception as err :
130+ logger . debug ( f"Discord Bot 关闭失败: { err } " )
131131
132132 self ._thread = threading .Thread (target = runner , daemon = True )
133133 self ._thread .start ()
@@ -142,8 +142,8 @@ def stop(self):
142142 finally :
143143 try :
144144 self ._loop .call_soon_threadsafe (self ._loop .stop )
145- except Exception :
146- pass
145+ except Exception as err :
146+ logger . error ( f"停止 Discord 事件循环失败: { err } " )
147147 self ._ready_event .clear ()
148148
149149 def get_state (self ) -> bool :
@@ -313,7 +313,8 @@ async def _delete_message(self, message_id: Union[str, int], chat_id: Optional[s
313313 logger .error (f"删除 Discord 消息失败:{ err } " )
314314 return False
315315
316- def _build_embed (self , title : str , text : Optional [str ], image : Optional [str ],
316+ @staticmethod
317+ def _build_embed (title : str , text : Optional [str ], image : Optional [str ],
317318 link : Optional [str ]) -> discord .Embed :
318319 description = ""
319320 fields : List [Dict [str , str ]] = []
@@ -337,7 +338,8 @@ def _build_embed(self, title: str, text: Optional[str], image: Optional[str],
337338 embed .set_image (url = image )
338339 return embed
339340
340- def _build_media_embeds (self , medias : List [MediaInfo ], title : str ) -> List [discord .Embed ]:
341+ @staticmethod
342+ def _build_media_embeds (medias : List [MediaInfo ], title : str ) -> List [discord .Embed ]:
341343 embeds : List [discord .Embed ] = []
342344 for index , media in enumerate (medias [:10 ], start = 1 ):
343345 overview = media .get_overview_string (80 )
@@ -358,7 +360,8 @@ def _build_media_embeds(self, medias: List[MediaInfo], title: str) -> List[disco
358360 embeds [0 ].set_author (name = title )
359361 return embeds
360362
361- def _build_torrent_embeds (self , torrents : List [Context ], title : str ) -> List [discord .Embed ]:
363+ @staticmethod
364+ def _build_torrent_embeds (torrents : List [Context ], title : str ) -> List [discord .Embed ]:
362365 embeds : List [discord .Embed ] = []
363366 for index , context in enumerate (torrents [:10 ], start = 1 ):
364367 torrent = context .torrent_info
@@ -384,7 +387,8 @@ def _build_torrent_embeds(self, torrents: List[Context], title: str) -> List[dis
384387 embeds [0 ].set_author (name = title )
385388 return embeds
386389
387- def _build_default_buttons (self , count : int ) -> List [List [dict ]]:
390+ @staticmethod
391+ def _build_default_buttons (count : int ) -> List [List [dict ]]:
388392 buttons : List [List [dict ]] = []
389393 max_rows = 5
390394 max_per_row = 5
@@ -398,7 +402,8 @@ def _build_default_buttons(self, count: int) -> List[List[dict]]:
398402 logger .warn (f"按钮数量超过 Discord 限制,仅展示前 { capped } 个" )
399403 return buttons
400404
401- def _build_view (self , buttons : Optional [List [List [dict ]]], link : Optional [str ] = None ) -> Optional [discord .ui .View ]:
405+ @staticmethod
406+ def _build_view (buttons : Optional [List [List [dict ]]], link : Optional [str ] = None ) -> Optional [discord .ui .View ]:
402407 has_buttons = buttons and any (buttons )
403408 if not has_buttons and not link :
404409 return None
@@ -429,8 +434,8 @@ async def _resolve_channel(self, userid: Optional[str] = None, chat_id: Optional
429434 return channel
430435 try :
431436 return await self ._client .fetch_channel (int (chat_id ))
432- except Exception :
433- pass
437+ except Exception as err :
438+ logger . warn ( f"通过 chat_id 获取 Discord 频道失败: { err } " )
434439
435440 # 私聊
436441 if userid :
@@ -446,7 +451,8 @@ async def _resolve_channel(self, userid: Optional[str] = None, chat_id: Optional
446451 if not channel :
447452 try :
448453 channel = await self ._client .fetch_channel (self ._channel_id )
449- except Exception :
454+ except Exception as err :
455+ logger .warn (f"通过配置的频道ID获取 Discord 频道失败:{ err } " )
450456 channel = None
451457 self ._broadcast_channel = channel
452458 if channel :
0 commit comments