以空格为单个字符串的参数来自不和谐输入
晚上好。在正常情况下,在函数中使用空格的争论只需要您用引号封装参数。这适用于大多数用途,但是这是因为我使用Discord接口来处理输入而有所不同。
我正在根据用户输入来获取Wikipedia文章:
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或Wikipedia API中的问题,我的问题更广泛。如果用户尝试输入传输安全层,则仅查询第一个单词(传输),因为所有空间都被视为单独的参数的单独参数。 您将如何将输入视为单个参数?我尝试在代码中格式化和替换空格,但是到目前为止,我唯一的解决方案是手动引用不和谐中的输入。
一如既往地感谢您抽出宝贵的时间!任何建议都将不胜感激。
我的 ://i.sstatic.net/wui14.png“ alt =”第二个示例显示了我当前的解决方案。
Good evening. In normal cases, taking an argument with spaces in a function only requires you to encapsulate the argument with quotes. This works for most uses, but this one differs since I'm using the Discord interface to process inputs.
I'm fetching a Wikipedia article based on user input:
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.
This is not an issue that lies within Discord.py or the Wikipedia API, my question is broader. If a user tries to input Transport Security Layer, only the first word (Transport) will be queried since all spaces are treated as separate arguments for separate parameters. How would you treat the input as a single argument? I have tried formatting and replacing spaces in the code, but as of now, my only solution is to manually quote the input in Discord.
Thank you as always for taking your time! Any suggestions at all are appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
有一个“消耗式恢复”参数选项。您可以阅读更多在这里。
There's a "consume rest" argument option. You can read more here.
另一种方法是从ctx.message.context获取整个字符串,然后自己操作。
Another way to do this is to get the entire string from ctx.message.context and just manipulate it yourself.