python - Need help on LMGTFY(Search) command for discord.py
问题描述
Im making a LMGTFY (Search) command. I want the bot to replace space with a + so instead of the bot saying https://lmgtfy.app/?q=test 1 I want it to say, https://lmgtfy.app/?q=test+1. Im new to python so Im sorry if this sounds like a very easy question to solve.
Here's my code:
@commands.command(aliases=["google"])
async def search(self, ctx, *, link):
await ctx.send(f"https://lmgtfy.app/?q={link}")```
解决方案
You can use str.replace()
for this:
@commands.command(aliases=["google"])
async def search(self, ctx, *, link):
await ctx.send(f"https://lmgtfy.app/?q={link.replace(' ', '+')}")
推荐阅读
- javascript - 需要为使用javascript动态创建的表添加复选框,希望能够过滤数据
- java - 如何找到 jar 存储信息的位置
- sql - 如何在派生列SQL中插入数据
- javascript - 返回值的 IIFE 比仅使用该值有什么好处?
- java - 如何从内部存储中读取文本文件?
- android - 如何在 API +30 中以编程方式使状态栏图标变亮和变暗
- python - 带和不带括号的类实例化
- python - 有没有办法在 pytest 中获取某些测试使用的所有夹具名称?
- python - 在 python 字节数组中创建灰度图像
- django - 在 DRF 序列化程序中访问一对一字段属性