Git Product home page Git Product logo

Comments (2)

lapin-b avatar lapin-b commented on August 17, 2024

I think it's time to share a few findings, in case I'm not the only one trying to catch the fish or somebody in the future finds a similar issue.

I have started writing a workaround (at least, what I thought was one) to deserialize the event manually and somehow call the proper event handler, using the raw event handler as such:

pub struct RawHandler;

#[async_trait]
impl RawEventHandler for RawHandler {
    async fn raw_event(&self, ctx: Context, ev: Event) {
        match ev {
            Event::Unknown(unknown_event) if unknown_event.kind == "GUILD_MEMBERS_CHUNK" => {
                warn!("Using workaround for GUILD_MEMBERS_CHUNK event");
                handle_raw_guild_members_chunk(&ctx, unknown_event).await;
            },

            _ => { /* No-op */ }
        };
    }
}

async fn handle_raw_guild_members_chunk(ctx: &Context, event: UnknownEvent) {
    let event_str = serenity::json::to_string_pretty(&event).unwrap();
    println!("{}", event_str);
    println!("{:?}", event);

    let chunk_event = match serenity::json::from_value::<GuildMembersChunkEvent>(event.value) {
        Ok(chunk_event) => chunk_event,

        Err(why) => {
            error!("Deserialization error\n{:?}", why);
            return;
        }
    };
}

I have printed the stringified event and its deserialized representation to later check for discrepancies between Discord's documentation and the implementation of the data structures.

Then, I took this bit of code for a spin by compiling and running the program before continuing writing the code. The deserialization operation returns an error: Json(Error("invalid type: sequence, expected a map", line: 0, column: 0)).

When taking a closer look at Discord's documentation about the GUILD_MEMBERS_CHUNK event, the members property is an array. In Rust, that property is typed as a HashMap<UserId, Member>.

from serenity.

mkrasnitski avatar mkrasnitski commented on August 17, 2024

Thank you for diagnosing this. The culprit is #2287, which simplified the Deserialize impl for GuildMembersChunkEvent but forgot to make sure the hashmap was being constructed out of the array rather than being directly deserialized.

from serenity.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.