Command raised an exception: TypeError: Misc.search() missing 1 required keyword-only argument: 'message'

Command raised an exception: TypeError: Misc.search() missing 1 required keyword-only argument: 'message'

我一直在为我的 discord 机器人制作这个 google 搜索功能,但我不断收到上面显示的错误。我已经尝试了很多事情,但似乎无法解决。这是我的代码:

@commands.command()
async def search(self, ctx, *, arg, message):
    gsearch = ctx.message.content
    URL = f'https://serpapi.com/search.json?q={gsearch}&tbm=isch&ijn=0&api_key={token}'
    if ctx.message.content in blacklistsearch:
        await ctx.send("You cant do that!")
    else:
        await ctx.send(URL)

*后不能有两个参数,只能有一个。根据您的代码,您无论如何都不需要 'message' 参数,只需要 'arg'。还有其他问题你也会 运行 陷入,例如你将整个消息作为参数,而不是你在 !search 之后写的内容。请查看下面修改后的代码以及示例图像。

@commands.command()
async def search(self, ctx, *, arg):
    gsearch = arg.lower()
    # so if you write "!search EXAMPLE test"
    # -> gsearch = "example test"
    URL = f'https://serpapi.com/search.json?q={gsearch}&tbm=isch&ijn=0&api_key={token}'
    if any(word in gsearch for word in blacklistsearch):
        # if any of the words in blacklistsearch is in gsearch
        await ctx.send("You cant do that!")
    else:
        await ctx.send(URL)

请注意,为了测试,发送的是 gsearch 而不是上图中的 URL