【问题标题】:Multiple arguments seperated with a comma in discord.py rewrite?discord.py重写中用逗号分隔的多个参数?
【发布时间】:2021-09-24 19:23:40
【问题描述】:

我的 discord bot 有以下代码,它基本上是一个图像处理命令,但我不知道如何用逗号分隔 2 个参数,在旧的 discord.py 中我只会使用“message.content .split(",")",但它似乎在 discord.py 重写中不再起作用,关于如何做到这一点的任何建议或想法? 代码:

async def topone(ctx, *, frstInput = "Tartarus", scndInput = "riot"):
    for attachment in ctx.message.attachments:

        await attachment.save("toponeimg.png")
        back_im = Image.open("toponetemplate.png")
        imre = Image.open("toponeimg.png")
        imre_resize = imre.resize((207, 116))
        back_im.paste((imre_resize), (38, 29))
        draw = ImageDraw.Draw(back_im)
        imgFont = ImageFont.truetype("C:/Users/Flippy/AppData/Local/Microsoft/Windows/Fonts/Montserrat-Semibold.ttf", 34)
        imgFont2 = ImageFont.truetype("C:/Users/Flippy/AppData/Local/Microsoft/Windows/Fonts/Montserrat-Semibold.ttf", 24,)


        draw.text((318, 74), frstInput, (0, 0, 0), font=imgFont, anchor="ls")
        # 'scndInput' is the argument I want to specify after a command, like "!topone Arg1, Arg2"
        draw.text((262, 112), scndInput, (74, 74, 74), font=imgFont2, anchor="ls")


        back_im.save("follow_hourly_bbc_on_twitter.png", quality=68)
        await ctx.send(file = discord.File("follow_hourly_bbc_on_twitter.png"))
        return

【问题讨论】:

    标签: python discord discord.py


    【解决方案1】:

    您可以将所有文本作为单个字符串,然后用逗号将其拆分

    async def topone(ctx, *, content):
        first_input, second_input = content.split(",")
        ...
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-06-03
      • 1970-01-01
      • 2020-12-04
      • 2018-11-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多