从 Discord 输入中将带空格的参数作为单个字符串

Take an argument with spaces as a single string from Discord input

晚上好。在正常情况下,函数中带空格的参数只需要用引号将参数封装起来。这适用于大多数用途,但这个不同,因为我使用 Discord 界面来处理输入。

我正在根据用户输入获取维基百科文章:

import wikipedia
...

@commands.command()
async def wiki(self, ctx, wiki):  # How would I treat the wiki parameter as a single argument?
        page = wikipedia.page(wiki, auto_suggest=False, redirect=True, preload=False)  # Fetch Wikipedia page.
        embed = discord.Embed(title=page.title, url=page.url, description=page.summary)  # Create a fancy embed.
        await ctx.send(embed=embed)  # Send embed in current channel.

这不是 Discord.py 或维基百科 API 中的问题,我的问题更广泛。如果用户尝试输入 Transport Security Layer,将仅查询第一个词 (Transport),因为所有空格都被视为单独参数的单独参数。 您如何将输入视为单个参数?我已经尝试格式化和替换代码中的空格,但截至目前,我唯一的解决方案是在 Discord 中手动引用输入。

一如既往地感谢您抽出宝贵时间!任何建议都表示赞赏。

有一个“消耗休息”参数选项。您可以阅读更多 here.

@commands.command()
async def wiki(self, ctx, *, wiki):

另一种方法是从 ctx.message.context 中获取整个字符串,然后自己操作它。

@commands.command()
async def wiki(self, ctx: commands.Context):
    wiki = ctx[6:]