From 58eb406c07e923771728d5e65a5891fe84a5ac1b Mon Sep 17 00:00:00 2001 From: Ching Date: Fri, 10 May 2024 11:07:53 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E4=B8=8D=E5=88=B0=E6=88=98=E6=8A=A5=E7=9A=84=E9=97=AE=E9=A2=98?= =?UTF-8?q?=20TUN-51=20catch=20=E5=8F=91=E9=80=81=E6=B6=88=E6=81=AF?= =?UTF-8?q?=E6=97=B6=E7=9A=84=20error?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- discord_bot.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/discord_bot.py b/discord_bot.py index efa97e3..df1f9f1 100644 --- a/discord_bot.py +++ b/discord_bot.py @@ -44,7 +44,10 @@ async def send_message(channel): for match_ in matches: data = dota.serialize_match_for_discord(match_) logger.info(f"sending match {match_['match_id']}, {data}") - await channel.send(content=data['content'], embeds=[discord.Embed.from_dict(embed) for embed in data['embeds']]) + try: + await channel.send(content=data['content'], embeds=[discord.Embed.from_dict(embed) for embed in data['embeds']]) + except Exception as e: + logger.error(f"send match error {e}") @bot.command(description="获取最近战绩", name='recent_matches') # this decorator makes a slash command async def get_friends_recent_matches(ctx, name, match_count=5): # a slash command will be created with the name "ping" @@ -56,7 +59,13 @@ async def get_friends_recent_matches(ctx, name, match_count=5): # a slash comman await ctx.respond(content=f'找不到 {name} 的信息') return data = dota.Friend.serialize_recent_matches_for_discord(friends, match_count) - await ctx.respond(content=data['content'], embeds=[discord.Embed.from_dict(embed) for embed in data['embeds']]) + if not data: + await ctx.respond(content=f'找不到 {name} 的战绩') + return + try: + await ctx.respond(content=data['content'], embeds=[discord.Embed.from_dict(embed) for embed in data['embeds']]) + except Exception as e: + logger.error(f"send recent_matches error {e}") @bot.command(description='获取朋友', name='list_friends') async def get_friends(ctx):