【问题标题】:how can i turn ' into %27 for this command?我怎样才能把这个命令的 ' 变成 %27 ?
【发布时间】:2021-06-14 19:02:09
【问题描述】:

我正在尝试创建一个命令,该命令将为您创建指向特定站点的链接,但有一个问题,其中有 ' 之类的东西,例如“上帝的旨意”,如果我在命令中使用 '它不会起作用,因为在链接中 ' 被 %27 替换,有没有办法在这个命令中自动将 ' 变成 %27?

@client.command()
async def mlwiki(ctx, *args):
    embed = discord.Embed(title="Your Wiki search:", description='**[Results](https://monsterlegends.fandom.com/wiki/{})**'.format('_'.join([arg.capitalize() for arg in args])), color=0x00ff00)
    embed.set_footer (text ="Atention!,if you put the terms wrong,the link won't work")
    await ctx.reply(embed=embed,mention_author=False)

【问题讨论】:

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


    【解决方案1】:

    使用 urllib

    from urllib.parse import quote
    
    string = "your url with ' "
    
    print(quote(string))
    >>> your%20url%20with%20%27%20
    

    它将您的字符串编码为良好的 url 格式

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-01-28
      • 2017-11-14
      • 2020-06-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-07-12
      相关资源
      最近更新 更多