Search code examples
stringdiscordargumentsbotscapitalize

How to join two strings in one line discord bot


I need to join and capitalize arguments at the same time. Here's what I have:

@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 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)))
    await ctx.channel.send('https://antmap.coc.tools/images/{}.png '.format('.'.join(args)))

and I need the arguments (it is always 1 - 3 args) to be capitalized before they are joined in the antmap... link I want this: !acz map cAmponotus herculeanus (when I misspell, the bot automatically corrects it into: Camponotus herculeanus) in Discord to work just like !acz map Camponotus herculeanus (which works fine and the bot responds in the channel with: Mapa výskytu: arguments. I have no idea how to make it work and if it is even possible, but it would be awesome! thx


Solution

  • >>> args = ["tHis", "Is", "sOme", "senTence"]
    >>> " ".join([arg.capitalize() for arg in args])
    'This Is Some Sentence'
    

    My args is just some example. Your args is already an list of strings.

    If you just want to capitalize the first word:

    " ".join(args).capitalize()