【问题标题】:How Should I Give Int In def discord.py我应该如何在 def discord.py 中给出 Int
【发布时间】:2021-05-13 09:31:47
【问题描述】:

嗨,我想给 int,我编码了这个

async def limit(ctx, amount : int):
    await ctx.send("Limit is : "+amount)

但我得到了这个错误: TypeError:只能将str(不是“int”)连接到str

我该怎么办?

【问题讨论】:

    标签: python-3.x discord discord.py


    【解决方案1】:

    将整数改为字符串。

    async def limit(ctx, amount : int):
        await ctx.send("Limit is : "+str(amount))
    

    【讨论】:

      【解决方案2】:

      将整数转换为字符串、格式化字符串或使用 f-strings

      await ctx.send("Limit is : " + str(amount)) # casting
      await ctx.send("Limit is : {}".format(amount)) # formatting
      await ctx.send(f"Limit is : {amount}") # f-string
      

      【讨论】:

        猜你喜欢
        • 2010-09-27
        • 1970-01-01
        • 2014-05-28
        • 2020-12-16
        • 1970-01-01
        • 2022-08-15
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多