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):