-1

lets say I have an on_message event that sees if the message has "pick crocka"

@client.event
async def on_message(message):
 if "pick crocka" in message.content.lower():

I want him to pick the part in the message where 2 or more stuff are inside parentheses, split with ,s likes this:

> pick crocka, do you like pizza with pinapple? (i like it, i hate it)

> hmmm, id say i hate it

(note that he would pick stuff randomly, I know the random.choice() part, all I need is how I can take only the part inside parentheses

Tom McLean
  • 5,583
  • 1
  • 11
  • 36
PyNoodle
  • 11
  • 3
  • Sorry man but your explanation is really confusing. Could you rephrase it in another way? – Zack VT Jun 17 '21 at 14:32
  • maybe this can help: https://stackoverflow.com/questions/4894069/regular-expression-to-return-text-between-parenthesis – Hoxha Alban Jun 17 '21 at 14:34

1 Answers1

2

You could use the following:

import re
message = """pick crocka, do you like pizza with pinapple? (i like it, i hate it)"""
options = re.search(r'\(.*?\)', message).group(0)[1:-1].split(", ")
print(options)

output:

['i like it', 'i hate it']
Tom McLean
  • 5,583
  • 1
  • 11
  • 36