Comments (2)
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.
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)
- Missing API endpoints for guild onboarding
- Feature not properly Guarded HOT 1
- Clear up reaction events and add missing fields/super reaction support
- impl From<EmojiId> for ReactionType doesn't produce a valid reaction HOT 1
- field name inconsistency for `FullEvent`.
- Cache results of methods that request data using `Http` HOT 1
- Build fails on Mac because .cargo/config.toml has CPU architecture set to haswell HOT 2
- No variant or associated item named `Member` found for enum `serenity::all::Action` in the current scope. HOT 4
- Error in CurrentApplicationInfo causing crash in certain case
- Messages should be truncated from cache when `Settings::max_messages` is lower than current cached messages
- CreateAttachment's item-level documentation is outdated HOT 1
- New `MessageType` documented
- Invalid Type Error HOT 3
- I don't receive the GuildCreate and GuildDelete events (for when the bot joins / gets kicked from a guild) HOT 3
- Proposal: Icon Change HOT 3
- set_presence from outside an event / command? How can I access serenity's Context from an outside event loop so i can change the presence? HOT 2
- Update to the monetization API
- little spelling error in the implementation of MessageReaction Struct HOT 1
- Message Command fails on messages with reactions (Unknown Event) HOT 1
- Serenity won't accept Discord Token no matter what HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from serenity.