【问题标题】:Discord Python whats wrong with my code?Discord Python 我的代码有什么问题?
【发布时间】:2018-03-09 10:21:35
【问题描述】:

我的代码已关闭,我在 args 上收到错误“SyntaxError: invalid syntax”

   @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')

【问题讨论】:

    标签: python discord


    【解决方案1】:

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

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

    是正确的。

    【讨论】:

      【解决方案2】:

      确定最后一行的“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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2017-10-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多