如何将函数的参数连接起来形成一个字符串?

2024-10-01 13:41:39 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图从changegame函数的属性中获取一个字符串,以便更改我正在开发的bot的状态。在

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

这不会导致识别字符串,但会导致:

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


Tags: theto函数字符串game属性状态bot
1条回答
网友
1楼 · 发布于 2024-10-01 13:41:39

要解决初始问题,请尝试一个简单的连接:

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

然而,你更大的问题是:

^{pr2}$

在这里,您正在将一个元组传递给discord.Game,您确定这是正确的吗?如果要像这样调用初始函数:changegame("League of Legends"),则需要修改函数定义:

async def changegame(game_chosen: str)

我怀疑这就是你想做的。在

相关问题 更多 >