'Command raised an exception: TypeError: Misc.search() missing 1 required keyword-only argument: 'message'
I have been making this google search function for my discord bot and i keep getting the error shown above. I've tried many things but cant seem to work it out. Heres my code:
@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)
Solution 1:[1]
You cannot have two arguments after *, you can only have one. Based on your code, you won't need the 'message' argument anyway, only 'arg'. There are other problems you will run into too, such as the fact that you are taking in the whole message as an argument, rather than what you've written after !search. Do view the revised code below, as well as an example image.
@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)
Please note that for the sake of testing, gsearch was sent instead of URL in the above image.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Bagle |

