is there a way to make discord.py copy a certaint part of the text sent by users
Question:
Is there any way for discord.py bot to copy a certain part of the message, for example:
The user sends print('hello')
in the chat, the bot responds with the text in the brackets, in this case hello
.
Answers:
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
Is there any way for discord.py bot to copy a certain part of the message, for example:
The user sends print('hello')
in the chat, the bot responds with the text in the brackets, in this case hello
.
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