python3怎么运⾏脚本_如何保持Python3脚本(Bot)的运⾏(不是英语母语,很抱歉可能是蹩脚的英语。我也是个编程新⼿)。
你好,我正在尝试使⽤QueryServer连接到TeamSpeak服务器以⽣成机器⼈程序。经过⼏天的挣扎。。。它很管⽤,只有⼀个问题,⽽我却被那⼀个困住了。在
以下是我剧本中实际发⽣的事情的总结:它连接在⼀起。在
它检查通道ID(以及它⾃⼰的客户端ID)
它加⼊了英吉利海峡
脚本结束,因此断开连接。在
我的问题是:我怎样才能使它不断开?如何使脚本保持在“等待”状态,以便在有⼈在频道中键⼊“hi bot”时可以读取?阅读⽂本和回复⽂本所需的所有代码似乎都很容易编程,但我⾯临的问题是,我⽆法让bot“运⾏”,因为它在运⾏脚本时会⽴即关闭⽂件。在
更多信息:
我使⽤的是python3.4.1
在API中有⼀个名为on_event的函数,我想⼀直运⾏它。bot代码应该只运⾏⼀次,然后保持“等待”直到事件发⽣。我该怎么做?没有线索。在
代码:import ts3
import telnetlib
import time
class BotPrincipal:
def Conectar(ts3conn):
MiID = [i["client_id"] for i in ts3conn.whoami()]
ChannelToJoin = "[Pruebas] Bots"
<_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:
python新手代码你好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) #entra al canal
try:
print("Asking for notifications from: " + ChannelToJoin)
ts3conn.servernotifyregister(event="channel", id_=IDCanal)
ts3conn.servernotifyregister(event="textchannel", id_=IDCanal)
except ts3.query.TS3QueryError:
print("You have no permission to use the telnet command: servernotifyregister") print("------- Bot Listo -------")
except ts3.query.TS3QueryError:
print("You have no permission to use the telnet command: clientmove")
except ts3.query.TS3QueryError:
print("Error finding ID for " + ChannelToJoin + ". telnet: channelfind")
def EventHappened():
print("Doesn't work")
# Data needed #
USER = "thisisafakename"
PASS = "something"
HOST = "111.111.111.111"
PORT = 10011
SID = 1
if __name__ == "__main__":
with ts3.query.TS3Connection(HOST, PORT) as ts3conn:
ts3conn.login(client_login_name=USER, client_login_password=PASS)
ts3conn.use(sid=SID)
print("Connected to "+HOST)
BotPrincipal.Conectar(ts3conn)

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。