serenity
serenity copied to clipboard
guild_update uses new name in old_data
On the docs, it says:
Provides the guild's old full data (if available) and the new, albeit partial data.
Actions
[dependencies.serenity]
version = "0.8"
default_features = true
pub struct Handler;
impl EventHandler for Handler {
fn guild_update(
&self,
ctx: Context,
old_guild: Option<Arc<RwLock<Guild>>>,
new_guild: PartialGuild,
) {
if let Some(old_guild) = old_guild {
let data = old_guild.read();
if new_guild.name == data.name {
println!("Guild Updated: {} to {}", data.name, new_guild.name);
return;
}
println!("Guild Renamed: {} to {}", data.name, new_guild.name);
}
}
}
I renamed my Discord server from Old_Name to New_Name.
Expected
If old_guild isn't available, I don't expect it to print anything.
If old_guild is available, I expect it to print out: "Guild Renamed: OId_Name to New_Name"
Actual
It prints: "Guild Updated: New_Name to New_Name"
I propose closing this issue. The guild_update signature seems to have changed.
Cargo.toml
[dependencies]
tokio = { version = "1.0", features = ["macros", "rt-multi-thread"] }
serenity = { version = "0.10", default-features = false, features = ["client", "gateway", "rustls_backend", "model"] }
main.rs
use serenity::{async_trait, model::prelude::*, prelude::*};
struct Handler;
#[async_trait]
impl EventHandler for Handler {
async fn guild_update(&self, _ctx: Context, new_data: PartialGuild) {
println! {"new_data.name:\n{:#?}", new_data.name};
}
}
#[tokio::main]
async fn main() {
let token = "REDACTED";
let mut client = Client::builder(&token)
.event_handler(Handler)
.await
.expect("Err creating client");
if let Err(why) = client.start().await {
println!("Client error: {:?}", why);
}
}
There is no old_guild in 0.10.8. In my tests, new_data.name contains the new name of the updated Discord channel.
I made a better (but still unsuccessful) attampt at replicating the issue, this time with cache.
Cargo.toml
[dependencies]
tokio = { version = "1.0", features = ["macros", "rt-multi-thread"] }
serenity = { version = "0.10", default-features = false, features = ["client", "gateway", "rustls_backend", "model", "cache"] }
main.rs
async fn guild_update(&self, _ctx: Context, old_data: Option<Guild>, new_data: PartialGuild) {
if let Some(od) = old_data {
println! {"old_data.name: {:#?}", od.name};
} else {
println! {"old_data was None"};
}
println! {"new_data.name: {:#?}", new_data.name};
}
When I changed the name of my Discord server from changeme to changed, the console printed:
old_data.name: "changeme"
new_data.name: "changed"
I cannot reproduce either

According to the code, the old guild data is retrieved before the update event is incorporated into the cache, which also seems correct
https://github.com/serenity-rs/serenity/blob/2eea7d792615c25ed904d08ec5931d935a314e9a/src/client/dispatch.rs#L604-L609
I propose we close this issue. It can be reopened if someone manages to reproduce after all