DISCORD BOT 如何搜索和替换 url 并获取不和谐输入

DISCORD BOT How to search and replace a url and getting the discord input

我如何让我的 discord 机器人接受一个播放器的任何输入,上面写着 +search debuunked

当我说它将在最后 URL 中添加 debuunked 时:

https://www.facebook.com/ 我想在斜杠后添加 debuunked,请帮助我谢谢 :) 使用 DISCORD.PY

if message.content == '+search' + "%s" + str(message):
    await message.channel.send(f"https://www.facebook.com/{message}")

这是我的代码^^

编辑:如果要检查消息是否以“+search”开头,可以使用以下代码

这段代码的作用是使用 startswith 函数。此函数识别字符串初始字符何时与您作为参数引入的字符匹配。

然后,一旦它被肯定地检查,使用 message.content.replace('+search ','') 你所做的就是用字符串替换一个空的 space,这样你只保留message.content 中的所有内容,除了初始字符串。

if message.content.startswith('+search '):
    await message.channel.send(f"https://www.facebook.com/{message.content.replace('+search ','')}")