-1

I decided to somehow do a Google search through discord.py wrote the code

@bot.event
async def on_message(message):
    if message.content.startswith('just google'):
        searchContent = ""
        text = str(message.content).split(' ')
        for i in range(2, len(text)):
            searchContent = searchContent + text[i]

        for j in search(searchContent, tld="co.in", num=1, stop=1, pause=2):
            await message.channel.send(j)

used this to make it all work: pip install beautifulsoup4 pip install google

the command works, but the rest of the bot commands do not work like

@bot.command()
async def Meme(ctx):

here most likely you need to rework the beginning of the code for a similar like

@bot.event
async def google(ctx):
        searchContent = ""
        text = str(message.content).split(' ')
        for i in range(2, len(text)):
            searchContent = searchContent + text[i]

        for j in search(searchContent, tld="co.in", num=1, stop=1, pause=2):
            await message.channel.send(j)

but this code only shows how to do it, it won't work. in fact I don't know how to make something similar to the last code

Сode
  • 1

1 Answers1

-1

That's because you have overwritten the on_message event.

I recommend you to do the "Google command" as a @bot.command()

Anyway you can also just put this on the end of the on_message event:

await bot.process_commands(message)

@bot.event
async def on_message(message):
    # do some extra stuff here

    await bot.process_commands(message)

this will call the coroutine that is on the original on_message

Davi A. Sampaio
  • 374
  • 2
  • 12