Package: ts3API
Simple Python API for the Teamspeak 3 Server Query APIPython 3 API that allows interactive access to the Teamspeak 3 Server Query interface.InstallationEither clone the GitHub repository and use local imports, or install it viapip:pip install ts3APIIf you want to use SSH connections also install the optional dependency Paramiko:pip install paramikoCode Examplefromts3API.TS3ConnectionimportTS3Connectionimportts3API.EventsasEventsHOST="serverhost"PORT=10011# Default PortUSER='serveradmin'# Default loginPASS='password'DEFAULTCHANNEL='Botchannel-or-any-other'SID=1# Virtual server idNICKNAME="aName"defon_event(sender,**kw):"""Event handling method"""# Get the parsed event from the dictionaryevent=kw["event"]print(type(event))"""# This generates output for every event. Remove the comment if you want more outputfor attr, value in event.__dict__.items():print("\t"+attr+":", value)"""ifisinstance(event,Events.ClientBannedEvent):print("Client was banned!")print("\tClient ID:",event.client_id)print("\tReason Message:",event.reason_msg)print("\tInvokerID:",event.invoker_id)print("\tInvokerName:",event.invoker_name)print("\tBantime:",event.ban_time)ifisinstance(event,Events.ClientKickedEvent):print("Client was kicked!")print("\tClient ID:",event.client_id)print("\tReason Message:",event.reason_msg)print("\tInvokerID:",event.invoker_id)print("\tInvokerName:",event.invoker_name)ifisinstance(event,Events.ClientLeftEvent):print("Client left!")print("\tClient ID:",event.client_id)print("\tReason Message:",event.reason_msg)iftype(event)isEvents.TextMessageEvent:# Prevent the client from sending messages to itselfifevent.invoker_id!=int(ts3conn.whoami()["client_id"]):ts3conn.sendtextmessage(targetmode=1,target=event.invoker_id,msg="I received your message!")# Connect to the Query Portts3conn=TS3Connection(HOST,PORT)# Login with query credentialsts3conn.login(USER,PASS)# Choose a virtual serverts3conn.use(sid=SID)# Find the channel to move the query client tochannel=ts3conn.channelfind(pattern=DEFAULTCHANNEL)[0]["cid"]# Give the Query Client a namets3conn.clientupdate(["client_nickname="+NICKNAME])# Move the Query clientts3conn.clientmove(channel,int(ts3conn.whoami()["client_id"]))# Register for server wide eventsts3conn.register_for_server_events(on_event)# Register for private messagests3conn.register_for_private_messages(on_event)# Register for channel message in botchannelts3conn.register_for_channel_events(channel,on_event)# Start the loop to send connection keepalive messagests3conn.start_keepalive_loop()For a more elaborated example of this API see the ts3Bot project:https://github.com/Murgeye/ts3BotCalling functions not explicitly implementedThanks to Chrisg2000's contribution, the API implements any command accepted by a TeamSpeak3 server.
You can call any command mentionend in the server query manual (should come with you server
installation) using keyword arguments, even if it's not explicitly implemented in code. See this
code snippet for example:servergroupaddclient(sgid=servergroup_id, cldbid=client_db_id)Theservergroupaddclientcommand is not currently implemented explicitly. However, you can still
call it if you know the parameters it need (sgid and cldbid).TroubleshootingFor general troubleshooting please also have a look at the troubleshooting section
inhttps://github.com/Murgeye/ts3Bot. If any questions remain, feel free to open an issue.