(Not native English, sorry, maybe broken English. I'm also new to programming).
Hi, I am trying to connect to a TeamSpeak server using QueryServer to make a bot. After a few days fighting it ... it works, with only one problem, and I'm stuck with that.
If you need to check, this is the TeamSpeak API I use: http://py-ts3.readthedocs.org/en/latest/api/query.html
And this is a summary of what is actually happening in my script:
- He is connecting.
- It checks the channel identifier (and the clientβs own identifier)
- He joins the channel
- Script terminates, so it shuts down.
My question is: how can I do this, it doesn't turn off? How can I make a script stand by so that it can read if someone types "hi bot" in a channel? All the code necessary for reading texts and answering them seems easy to program, however, I face a problem when I can not support the "launch" of the bot, because it closes the file as soon as it finishes working with the script.
Additional Information:
I am using Python 3.4.1 .
I tried to learn Threading http://www.tutorialspoint.com/python/python_multithreading.htm , but either M'm is dumb or it doesn't work like me. There is a function in the API called on_event that I would like to keep working all the time. The bot code should be run only once, and then remain βpendingβ until an event occurs. How can I do it? There is no clue.
The code:
import ts3 import telnetlib import time class BotPrincipal: def Conectar(ts3conn): MiID = [i["client_id"] for i in ts3conn.whoami()] ChannelToJoin = "[Pruebas] Bots" ts3conn.on_event = BotPrincipal.EventHappened() try: BuscandoIDCanal = ts3conn.channelfind(pattern=ChannelToJoin) IDCanal = [i["cid"] for i in BuscandoIDCanal] if not IDCanal: print("No channel found with that name") return None else: MiID = str(MiID).replace("'", "") MiID = str(MiID).replace("]", "") MiID = str(MiID).replace("[", "") IDCanal = str(IDCanal).replace("'", "") IDCanal = str(IDCanal).replace("]", "") IDCanal = str(IDCanal).replace("[", "") print("ID de canal " + ChannelToJoin + ": " + IDCanal) print("ID de cliente " + Nickname + ": " + MiID) try: print("Moving you into: " + ChannelToJoin) ts3conn.clientmove(cid=IDCanal, clid=MiID)
source share