Skip to content

Python @On functions inside class #2828

Answered by miranda1000
miranda1000 asked this question in Q&A
Discussion options

You must be logged in to vote

Putting the function inside the constructor seems to work, but is there any cleaner way to do it?

class MineflayerClient:
	def __init__(self, ...):
		...
		
		self._bot = mineflayer.createBot({
			"host": host,
			"port": port,
			"username": username,
			"port": port
		})
		
		@On(self._bot, "login")
		def login(this):
			print(this._username + " connected to the server (" + this.server + ")")

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@miranda1000
Comment options

Answer selected by miranda1000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant