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

Why does my discord bot give the following error?

I don’t understand why it gives this error! It’s eating my head

 @client.event
    async def on_message(message):
        # Make sure bot doesn't get stuck in an infinite loop
        if message.author == client.user:
            return

        # Get data about the user
        username = str(message.author)
        user_message = str(message.content)
        channel = str(message.channel)

        # Debug printing
        print(f"{username} dice: '{user_message}' ({channel})")

        # If the user message contains a '?' in front of the text, it becomes a private message
        if user_message[0] == '?':
            user_message = user_message[1:]  # [1:] Removes the '?'
            await send_message(message, user_message, is_private=True)
        else:
            await send_message(message, user_message, is_private=False)

The only thing it does there is call a module called "send_message"

async def send_message(message, user_message, is_private):
     try:
         response = responses.handle_response(user_message)
         await message.author.send(response) if is_private else await message.channel.send(response)
     except Exception as e:
         print(e)
def handle_response(message) -> str:
     p__message = message.lower()
     if p__message == 'tell me something bana':
         return random.choice(bana_phrases)

400 Bad Request (error code: 50006): Cannot send an empty message

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

>Solution :

You should use a check to make sure handle_response function returns a string (it does not if the message is not tell me something bana):

async def send_message(message, user_message, is_private):
     try:
         response = responses.handle_response(user_message)
         if response:
              await message.author.send(response) if is_private else await message.channel.send(response)
     except Exception as e:
         print(e)
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