Discord Python我的代码有什么问题吗?

时间:2017-09-27 19:52:56

标签: python discord

我的代码已关闭,我收到错误'语法错误:语法无效'在args

   @client.command(pass_context=True)
   async def render(*args, message):
      """Renders A Growtopia World"""
      mesg = ' '.join(args)
      await client.say(":earth_americas: World Render:")
      return await client.say('https://www.growtopiagame.com/worlds/'mesg'.png')

2 个答案:

答案 0 :(得分:0)

*args, **kwargs总是出现在参数的末尾。

async def render(message, *args):
    ...

是对的。

答案 1 :(得分:0)

当然,这不是语法错误,而是#g; mesg'在最后一行?因为这不是在Python中连接字符串的方式。

有许多方法可以格式化或连接字符串(最明显的一种方法就是像这样添加它们:string_sum = string1 + string2),但是我个人最喜欢的字符串格式化与变量结合等等,如果在Python 3.6+上,是f字符串(https://cito.github.io/blog/f-strings/)。

所以在这种情况下你要client.say(f'https://www.growtopiagame.com/worlds/{mesg}.png')

(P-EDIT:Godron有点正确,取决于Python 2或3.如果有更多详细信息,请参阅此SO答案https://stackoverflow.com/a/5940226/4192226

相关问题