首页 > 解决方案 > 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}")```

标签: pythondiscord.py

解决方案


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(' ', '+')}")

推荐阅读