Azula
Azula

Reputation: 5

how can I use multiple "on_message" which are working?

@client.event
async def on_message(message):
    if message.content.startswith("hey"):
        await message.reply('こんにちは', mention_author=True)

    await client.process_commands(message)

@client.event
async def on_message(message):
    if message.content.startswith("test"):
        await message.reply('123', mention_author=True)

    await client.process_commands(message)

I have these 2 on_message and doesn't matter how much I will create only the last I'v created will work, in this case my test only works and I saw the await client.process_commands(message) fix that the other commands works and it do but I can't do multiple on_message so please help

Upvotes: 0

Views: 156

Answers (1)

Landon Harter
Landon Harter

Reputation: 105

Why do you need multiple of the method? Just combine all of the code from the methods and put it in one.

For example:

@client.event
async def on_message(message):
    if message.content.startswith("hey"):
        await message.reply('こんにちは', mention_author=True)
    if message.content.startswith("test"):
        await message.reply('123', mention_author=True)
    
    await client.process_commands(message)

Upvotes: 2

Related Questions