C
C#•4mo ago
Smoothy

How do i handle an event

Basically i want to do a console write when OnBotDisconnected event is fired (this is from MineSharp), from this i am getting Error CS0029 Cannot implicitly convert type void to MineSharp.Bot.Events.BotStringEvent
No description
7 Replies
Jimmacle
Jimmacle•4mo ago
you can't subscribe to an event with a statement, you have to subscribe by providing a method the simplest way is to put it in a lambda, like () => Console.Write("...");
Smoothy
Smoothy•4mo ago
Managed to fix it, turns out the event required more variables in the () for some reason.
Lecco
Lecco•4mo ago
Change your code like: private void BotDisconnected(object sender,Events.BotStringEventArgs e){ Console.Write("Disconnected");} bot.OnDisconnected+=this.BotDisconnected();
Jimmacle
Jimmacle•4mo ago
yeah, the event expects a method with a specific signature but i don't know myself since idk what library you're using you can use a lambda like i showed or a full-on method
Smoothy
Smoothy•4mo ago
GitHub
GitHub - psu-de/MineSharp: High-Level async API to build minecraft ...
High-Level async API to build minecraft bots. Contribute to psu-de/MineSharp development by creating an account on GitHub.
Jimmacle
Jimmacle•4mo ago
probably shouldn't have said so 😬
tannergooding
tannergooding•4mo ago
Minecraft modding is notably explicitly allowed by Mojang/Microsoft there are some limits around griefing servers, but the modding itself is fine