首页 > 解决方案 > 如何在一行中使用相同的参数两次?

问题描述

我的不和谐机器人有以下代码:

@bot.command(brief="Za map napiš Rod a druh a vyskočí ti mapa výskytu!")
async def map(ctx, *args):
    if not args:
        await ctx.channel.send("Nenapsal jsi Rod/ Rod a druh! \nVysvětlivka:")
        await ctx.channel.send(
            "https://cdn.discordapp.com/attachments/661985293834125342/808308254081417227/acz_map_command.png"
        )

    else:
        await ctx.channel.send('Mapa výskytu: *{}*'.format(
            ' '.join(args).capitalize()))
        await ctx.channel.send(
            'https://antmap.coc.tools/images/{}.png '.format(
                '.'.join(args).capitalize()))
        await ctx.channel.send('AntWiki: *{}*'.format(
            ' '.join(args).capitalize()))
        await ctx.channel.send(
            'https://antwiki.org/wiki/{}'.format(
                '_'.join(args).capitalize()))

问题在这里:

        await ctx.channel.send(
            'https://antmap.coc.tools/images/{}.png '.format(
                '.'.join(args).capitalize()))

Bot 在您使用命令后发送此信息:https://antmap.coc.tools/images/Argument1.Argument2.png

但现在我需要更改它,所以它发送 https://antmap.coc.tools/images/Argument1/Argument1.Argument2.png

它应该看起来像这样:

             'https://antmap.coc.tools/images/{}/{}.png'

或像这样:

'https://antmap.coc.tools/images/{}.png'.format(
                '/','.'.join(args).capitalize()

或类似的东西?

我已经搜索了一些答案,但我还无法弄清楚。

标签: pythonstringjoindiscordarguments

解决方案


尝试:

'https://antmap.coc.tools/images/{}/{}.{}.png'.format(arg1,arg1,arg2)

请参阅:https ://docs.python.org/3/tutorial/inputoutput.html#the-string-format-method


推荐阅读