Ruri
Ruri

Reputation: 150

How to get arguments for on_message event in discord.py

I'm currently new to coding, And I'm planning to make a utility bot. So basically, what I am trying to do here is getting the second argument for my on_message event. But how can I do that? I'm making an auto math module for my bot, without using the prefix. For example: solve 5*5 and the bot was supposed to automatically answer it by reading the second argument.

My Code:


@client.event
async def on_message(message):
    if message.content.startswith('solve'):
        expression = # Where it supposed to read the arguments
        await math(message, expression) # math function

Upvotes: 0

Views: 1082

Answers (1)

Titouan L
Titouan L

Reputation: 1173

Using message.content.startswith() means you already know that message.content is a string. It is self explanatory that it contains the content of the message that triggered this on_message() event, and you can find the doc here.

Considering that your input message is solve 5*5, you could use the method split() to get a list of the argument of the message.

msg = message.content.split()
# Here msg[0] is "solve"
expression = msg[1]
# Here expression = 5*5

Upvotes: 1

Related Questions