margobra8 margobra8 - 1 year ago 74
Python Question

How do I join the args of a function to form a string?

I am trying to obtain a string from the attributes of the

function in order to change the status of a bot i'm developing.

async def changegame(*game_chosen: str):
"""Changes the game the bot is playing"""
game_str = discord.Game(name=game_chosen)
await bot.change_status(game=game_str, idle=False)
await bot.say("```Game correctly changed to {0}```".format(game_chosen))

This does not result in the string being recognized but in this:

Game correctly changed to ('Test', 'string', '123')

Answer Source

To solve your initial issue, try a simple join:

' '.join(map(str, game_chosen))

However, your bigger problem is:

game_str = discord.Game(name=game_chosen)

Here you are passing a tuple to discord.Game, are you sure this is right? If you want to call your initial function like this: changegame("League of Legends"), then you need to fix your function definition:

async def changegame(game_chosen: str)

I suspect this is what you are actually trying to do.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download