Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Extra libraries, Code snippets, applications etc. » Applications created with U++ » Bot library for discord, bombs example adapted.
Re: Bot library for discord, bombs example adapted. [message #52670 is a reply to message #52668] Fri, 08 November 2019 14:33 Go to previous messageGo to previous message
jjacksonRIAB is currently offline  jjacksonRIAB
Messages: 227
Registered: June 2011
Experienced Member
In Discord.h I'd add

Event<> BeforeSocketReceive,
        WhenDisconnected;

and I'd call it from Discord.cpp

else if(ws.IsClosed()) {
    LOG("Socket closed unexpectedly");
    LOG(ws.GetError());
    WhenDisconnected();
    return;
}

Hopefully then I could just subscribe to that event and run Listen() again.
bot.WhenMessageCreated = [&](ValueMap payload) {
    String channel  = payload["d"]["channel_id"];
    String content  = payload["d"]["content"];
    String userName = payload["d"]["username"];
        
    if(content.StartsWith("!hello")) {
        bot.CreateMessage(channel, "hello, world!");
    }
};

bot.WhenDisconnected = [] { 
    bot.Listen();
};


I think your connection is just being hard killed from Discord's end without the courtesy of a Resume event.
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: U++ SSH package and Turtle in action (Videos)
Next Topic: UltimateOpenGL [BETA] 3D engine
Goto Forum:
  


Current Time: Mon Sep 01 01:29:07 CEST 2025

Total time taken to generate the page: 0.00273 seconds