Ask coding questions

← Back to all posts
pvk1ng (0)

Hello, Can someone help me. Im trying to make a discord bot with python but the other on_message events wont work after ive added a new one. How do I make it so im able to have multiple message/return events?

InvisibleOne (3001)

You can't create another on message event, you need to have it both in the first function.
After your first if statement asking if the content starts with Yo Mama, then you should use an elif statement for more, like this:

async def on_message(message):
  if == client.user:
  if message.content.startswith('Yo Mama'):
    #do something
  elif message.content.startswith('hello'):
   #do something else
  elif # and so on...
BruceLi2 (1)

you put them in the same def


async def on_message(message):
if == client.user:
if message.content.startswith('hello'):
if message.content.includes('yo mama'):
#etc, I think includes is also a property but I mainly use discord.js

Coder100 (18215)

put all the code in one function instead.

ChopSueyMaster (49)

Put the code in one of the function . You cant have 2 on_messages.