Skip to content

Instantly share code, notes, and snippets.

@11fl
Last active December 8, 2022 00:44
Show Gist options
  • Save 11fl/5845457 to your computer and use it in GitHub Desktop.
Save 11fl/5845457 to your computer and use it in GitHub Desktop.
IRC bot python 3
# -*- coding: utf-8 -*-
import socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
HOST = '' #irc server
PORT = 6665 #port
NICK = 'pony_bot'
USERNAME = 'megadeath'
REALNAME = 'little pony'
print('soc created |', s)
remote_ip = socket.gethostbyname(HOST)
print('ip of irc server is:', remote_ip)
s.connect((HOST, PORT))
print('connected to: ', HOST, PORT)
nick_cr = ('NICK ' + NICK + '\r\n').encode()
s.send(nick_cr)
usernam_cr= ('USER megadeath megadeath megadeath :rainbow pie \r\n').encode()
s.send(usernam_cr)
s.send('JOIN #mysupertest \r\n'.encode()) #chanel
while 1:
data = s.recv(4096).decode('utf-8')
print(data)
if data.find('PING') != -1:
s.send(str('PONG ' + data.split(':')[1] + '\r\n').encode())
print('PONG sent \n')
if data.find('hi') != -1:
s.send((str('PRIVMSG ' + data.split()[2]) + ' Hi! \r\n').encode())
s.close()
@SysKeyyy
Copy link

Why do i keep getting this error?
timeoutError: [WinError 10060] The connection attempt failed because the connected computer did not respond within a certain time or because the established connection to the host computer no longer works

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment