fix: 修复获取不到战报的问题 TUN-51 catch 发送消息时的 error

This commit is contained in:
Ching 2024-05-10 11:07:53 +08:00
parent 1e939a0f22
commit 58eb406c07

View File

@ -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}")
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)
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):