serenity-rs / serenity

A Rust library for the Discord API.
https://discord.gg/serenity-rs
ISC License
4.65k stars 571 forks source link

No variant or associated item named `Member` found for enum `serenity::all::Action` in the current scope. #2877

Closed Stay1444 closed 3 months ago

Stay1444 commented 3 months ago

I'm trying to handle the FullEvent::GuildAuditLogEntryCreate event, but when trying to match on the AuditLogEntry.action member variable the LSP gives the available options

    GuildUpdate,
    Channel(ChannelAction),
    ChannelOverwrite(ChannelOverwriteAction),
    Member(MemberAction),
    Role(RoleAction),
    Invite(InviteAction),
    Webhook(WebhookAction),
    Emoji(EmojiAction),
    Message(MessageAction),
    Integration(IntegrationAction),
    StageInstance(StageInstanceAction),
    Sticker(StickerAction),
    ScheduledEvent(ScheduledEventAction),
    Thread(ThreadAction),
    AutoMod(AutoModAction),
    CreatorMonetization(CreatorMonetizationAction),
    VoiceChannelStatus(VoiceChannelStatusAction),
    Unknown(u8),

But it then throws an error saying that it can't find that enum entry.

Happens when running cargo build too.

jamesbt365 commented 3 months ago

There are multiple Actions in serenity, thus both cannot be in serenity::all. Use the full path.

Stay1444 commented 3 months ago

I'm using the full path!

error[E0599]: no variant or associated item named `GuildUpdate` found for enum `serenity::all::Action` in the current scope
  --> src/event_handler.rs:43:40
   |
43 |                 serenity::all::Action::GuildUpdate => (),
   |                                        ^^^^^^^^^^^ variant or associated item not found in `Action`

The LSP completes that fine, and going to the definition shows me the correct Action enum.

jamesbt365 commented 3 months ago

LSP's aren't perfect, cargo check will always give you the right result. You need to use the full path of Action, serenity::all::Action is a reexport, not the full path.

The reexport points at serenity::model::guild::automod::Action not serenity::model::guild::audit_log::Action which you are intending to use here.

Stay1444 commented 3 months ago

That was it, thank you.