Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extending Presence doesn't affect all members? #4742

Closed
ObscuritySRL opened this issue Aug 25, 2020 · 2 comments · Fixed by #4744
Closed

Extending Presence doesn't affect all members? #4742

ObscuritySRL opened this issue Aug 25, 2020 · 2 comments · Fixed by #4744

Comments

@ObscuritySRL
Copy link
Contributor

ObscuritySRL commented Aug 25, 2020

Please describe the problem you are having in as much detail as possible:
If you extend Presence with, say, PresenceExt, some members will have Presence, some will have PresenceExt. It seems like they will always have PresenceExt after a legitimate presenceUpdate.

Include a reproducible code sample here, if possible:

//Formatting helps with my bad eyes. Don't shoot.

//Extend the Presence structure...
Discord.Structures.extend(
    'Presence',
    Presence => class PresenceExt extends Presence {
        //Give it a simple method to test...
        get isTwitchStreaming( ) {
            return this.activities.some( ( { name, type } ) => name === 'Twitch' && type === 'STREAMING' );
        }
    }
);


//Initialize the client...
const bot = new Discord.Client( {
    //I know, not recommended. I only use it for small, private bots...
    fetchAllMembers: true
} );


bot.on( 'ready', ( ) => {
    //Get a random guild...
    const guild = bot.guilds.cache.random( );;

    //Add up the PresenceExt and Presence...
    const results = guild.members.cache.reduce(
        ( results, { presence: { constructor: { name } } } ) => ( { ...results, [ name ]: 1 + ( results[ name ] ?? 0 ) } ),
        { }
    );

    //{ PresenceExt: 241, Presence: 2065 }...
    console.log( results );
} );


//These will all be PresenceExt...
bot.on( 'presenceUpdate', ( _, { constructor: { name } } ) => console.log( name ) );

Further details:

  • discord.js version: 12.2.0
  • Node.js version: 14.4.0
  • Operating system: Windows
  • Priority this issue should have – please be realistic and elaborate if possible: Low

Relevant client options:

  • partials: [ 'CHANNEL', 'GUILD_MEMBER', 'MESSAGE', 'REACTION', 'USER' ]
  • gateway intents: none
  • other: none
@SpaceEEC
Copy link
Member

This is due to GuildMember#presence and User#presence returning new Presence(...); when no presence is available for the member (or user), which does not account for extensions.

This should be fixable by returning something like new (Structures.get('Presence'))(...) instead.

@NotSugden
Copy link
Contributor

NotSugden commented Aug 25, 2020

This should be fixable by returning something like new (Structures.get('Presence'))(...) instead.

shouldn't it be this.client.presences.add(...) wait- that doesn't exist, what about this.guild.presences.add(...) on the GuildMember class?

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 13, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants