Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Trying to make a discord bot but on.message or message.content not working

I want the bot to use the gpt-3 API to answer questions but for some reason on.message is not working

import openai
import discord


openai.api_key = "apikey"

client = discord.Client()

@client.event

async def on_ready():
 print('online')

async def on_message(message):
   
    if message.content.startswith("!ask"):
        print('I read the message')
        

        question = message.content[5:]

        response = openai.Completion.create(
            engine="text-davinci-002",
            prompt=f"{question}\n",
            temperature=0.7,
            max_tokens=1024,
            top_p=1,
            frequency_penalty=0,
            presence_penalty=0
        )

        await message.channel.send(response.choices[0].text)


client.run('token')

Everything works fine and the ‘online’ appears but after that i don’t know what’s happening since i am not getting any errors (Sorry if its something obvious i am just now learning)

the

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

client.run('token')
open.api_key="apikey"

are obviously replaced with the real ones in my code

>Solution :

If you want to register an event, you have to put the client.event decorator on top of the event functions. Your on_message function certainly doesn’t have one, so just put one on it.

@client.event
async def on_message(message):
    ...
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading