pyCraft
pyCraft copied to clipboard
A bot that logs on a server and performs command
I wanna make a bot that will go on a server and perform some commands! I am totally new to coding and I want someone to help me out with installing the library and helping me make the bot If you could please send the code to me here and Ill learn from it! And you can contact me on discord at Invito#2765
I am pretty new aswell, but I have worked on something similar so here is my approach:
import time
time.sleep(2) #makes sure packets are send *after* connection is established
try:
packet = serverbound.play.ChatPacket()
packet.message = "/command argument1 argument2" #your command here
connection.write_packet(packet) #sends the packet
except KeyboardInterrupt: #exits more nicely
print("Bye!")
sys.exit()
I replaced lines 111-125 in start.py with the code above and it works very well.
You can add more commands by doing:
packet.message = "/command argument1 argument2"
connection.write_packet(packet)
time.sleep(command_cooldown) #you might need to wait between commands
packet.message = "/other_command argument1 argument2"
connection.write_packet(packet)
I hope this helped you :)