我正在构建一个不和谐的机器人,它会根据要求从 EpicGame 商店提供当前免费的游戏。我以示例中的代码为基础,并将其重新制作为机器人的输出。在页脚中,我想放置一个指向该页面的链接以获取游戏。为此,我需要从 api.get_free_games() 获取“productSluge”或以其他方式获取链接。
它不像那样工作
api.get_free_games()['productSluge']
我正在使用epicstore_api
我需要括号中的部分
https://www.epicgames.com/store/en/product/ <这部分>/home
或完整链接
完整的不和谐机器人命令:
@bot.command()
async def free(ctx):
"""Fetches current free games from the store."""
api = EpicGamesStoreAPI()
free_games = api.get_free_games()['data']['Catalog']['searchStore']['elements']
for game in free_games:
game_name = game['title']
game_thumbnail = None
# Can be useful when you need to also show the thumbnail of the game.
# Like in Discord's embeds for example, or anything else.
# Here I showed it just as example and won't use it.
for image in game['keyImages']:
if image['type'] == 'Thumbnail':
game_thumbnail = image['url']
# print(game_thumbnail)
game_price = game['price']['totalPrice']['fmtPrice']['originalPrice']
game_promotions = game['promotions']['promotionalOffers']
upcoming_promotions = game['promotions']['upcomingPromotionalOffers']
if not game_promotions and upcoming_promotions:
# Promotion is not active yet, but will be active soon.
promotion_data = upcoming_promotions[0]['promotionalOffers'][0]
start_date_iso, end_date_iso = (
promotion_data['startDate'][:-1], promotion_data['endDate'][:-1]
)
# Remove the last "Z" character so Python's datetime can parse it.
start_date = datetime.fromisoformat(start_date_iso)
end_date = datetime.fromisoformat(end_date_iso)
will = ('Игра будет бесплатна с {} по {} UTC.'.format(
start_date, end_date
))
emb = discord.Embed(title=game_name + game_price, description=will, colour=col['AQUA'])
emb.set_footer(text='url')
emb.set_image(url=game_thumbnail)
await ctx.send(embed=emb)
else:
emb = discord.Embed(title='Сейчас БЕСПЛАТНО!', description=game_name + game_price, colour=col['GOLD'])
emb.set_footer(text='url')
emb.set_image(url=game_thumbnail)
await ctx.send(embed=emb)
如果添加到循环中有效