is there any way for discord.py bot to copy a certain par of the messege, fore example:
the user sends "print('hello')" in the chat, the bot responds whit the text in the brackets, in this case "hello"
CodePudding user response:
Use regex
import re
from discord.ext import commands
bot = commands.Bot()
@bot.event
async def on_message(message):
content = message.content # in this case: print('hello')
# any character inside of '' (0 or more)
result = re.search(r'\'[^"]*\'', content).group(0)
# remove ' around string
result = result.strip("'")
await message.channel.send(result)
Result
hello