【发布时间】:2015-11-21 19:54:19
【问题描述】:
这是我的麻烦:Bot 很好地加载了 IRC 信息,但是当它假设要识别自己时,他没有。
以下是代码的相关部分。我猜问题出在第 9 行,但我不知道为什么。
import socket
server = #ServerName
channel = #ChannelName
botnick = #BotName
password = #Password (string)
def connect(channel, password): # This function is used on connect.
ircsock.send("PRIVMSG" + " :NICKSERV Identify " + password +"\n") #Problem Here
ircsock.send("JOIN "+ channel +"\n")
ircsock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
ircsock.connect((server, 6667)) # Here we connect to the server using the port 6667
ircsock.send("USER "+ botnick +" "+ botnick +" "+ botnick +":Just testing .\n") # user authentication
ircsock.send("NICK "+ botnick +"\n")
connect(channel, password) #Join the channel and identify the nick using the functions we previously defined
提前致谢。
解决方案: 通过将connect函数设置为posted,是第一个被调用的 然后服务器在 USER / NICK 之前尝试连接。
def create_connection():
global ircsock
ircsock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
ircsock.connect((server, 6667)) # Here we connect to the server using the port 6667
ircsock.send("USER "+ botnick +" "+ botnick +" "+ botnick +":This bot is a result of GStones mastery .\n") # user authentication
ircsock.send("NICK "+ botnick +"\n") # here we actually assign the nick to the bot
time.sleep(5)
connect(channel, password) # Join the channel and identify the nick using the functions we previously defined
create_connection()
谢谢i\OFF
【问题讨论】:
-
ircsock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
-
bot进入irc服务器但未执行connect函数,所以NickServ请求识别命令:“注意Botman:此昵称已注册。请选择不同的昵称,或通过/msg识别NickServ 识别 "
-
也尝试使用不同的botnick。
标签: python sockets bots irc identify