How to make a function that picks up data and drops in bot chat

Asked

Viewed 139 times

0

Good afternoon I have a bot for a site where I frequent and wanted to develop a function where it sends a private message in the system. In my head it seems simple but I can not execute (I know the code is wrong but this is how I imagined).

I’m new to programming and I wanted help on how to solve this.

It’s quite simple, the user would call /sms to the bot and soon after it would capture everything I had in front of /sms. Then he’d pick it up and play chat.

It would be a function to speak anonymously, someone can help me?

I know it’s a silly question but I have this question.

Thanks in advance.

(Edit) I managed to solve the problem but when I send the message it plays the code too!

Imagem

#private mensagem
def mensagemprivate(self, message, name_sender, to=''):
        if re.findall('/sms .*', message):
            self.post(message=message)

elif '/sms' in message:
        t_mensagemprivate = threading.Thread(target=self.mensagemprivate, args=(message, name_sender, id_sender))
        t_mensagemprivate.start()
  • Do not post code as image; the site has code support, just do the [tour] to better understand.

  • Seriously nobody knows how to help me how I can get this /sms out of the way .... ;~;

1 answer

0


You have two ways to remove the text /sms of your message.

One of them is using the function .replace, that replaces one string with another. In your case, you can replace it with an empty string:

...
elif '/sms' in message:
    message = message.replace('/sms ', '')  # Substituindo o texto por vazio
...

Or you can break your string at the position of the text you want to remove:

...
elif '/sms' in message:
    message = message[5:]  # Isto "corta" a string e retorna a partir do quinto caractere até seu fim
...
  • Thank you very much. I used the 2 example

Browser other questions tagged

You are not signed in. Login or sign up in order to post.