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

Type declarations lacking #4305

Closed
1 task
Pwuts opened this issue May 20, 2020 · 3 comments
Closed
1 task

Type declarations lacking #4305

Pwuts opened this issue May 20, 2020 · 3 comments

Comments

@Pwuts
Copy link

Pwuts commented May 20, 2020

Please describe the problem you are having in as much detail as possible:
I'm working on a Discord bot, and of course my IDE uses index.d.ts to autocomplete a lot of things. The problem is that the available TypeScript types are lacking the actual functionality of the library.

Example:

/* in index.d.ts */

interface ActivityOptions {
    name?: string;
    url?: string;
    type?: ActivityType | number;
    shardID?: number | number[];
}

vs

/* in Presence.js */

class Activity {
  constructor(presence, data) {
    /* condensed for pasting */
    this.name = data.name;
    this.type = ActivityTypes[data.type];
    this.url = data.url || null;
    this.details = data.details || null;
    this.state = data.state || null;
    this.applicationID = data.application_id || null;
    this.timestamps = data.timestamps
      ? {
          start: data.timestamps.start ? new Date(Number(data.timestamps.start)) : null,
          end: data.timestamps.end ? new Date(Number(data.timestamps.end)) : null,
        }
      : null;
    this.party = data.party || null;
    this.assets = data.assets ? new RichPresenceAssets(this, data.assets) : null;
    this.syncID = data.sync_id;
    this.flags = new ActivityFlags(data.flags).freeze();
    this.emoji = data.emoji ? new Emoji(presence.client, data.emoji) : null;
    this.createdTimestamp = new Date(data.created_at).getTime();
  }
}

I'm sure some of these properties are not intended to set externally, but I can now figure out how to set a custom status from neither the documentation nor the TypeScript declarations.

Further details:

  • discord.js version: v12.2.0
  • Node.js version: v14.x
  • Operating system: Windows / Ubuntu
  • Priority this issue should have: high
  • I have also tested the issue on latest master, commit hash:
@monbrey
Copy link
Member

monbrey commented May 20, 2020

That's because you cannot set a custom status for bots, which is why those properties are not part of the ActivityOptions type definition for setting activities.

You can, however, read the custom status of Users, which is why those properties are part of the definition of an Activity. These are constructed from PRESENCE_UPDATE events received from the gateway.

No functionality or typings here are incorrect, and the functionality you describe isn't documented because it doesn't exist.

@Pwuts
Copy link
Author

Pwuts commented May 20, 2020

Thanks for the clarification.

@Pwuts Pwuts closed this as completed May 20, 2020
@Pwuts
Copy link
Author

Pwuts commented May 20, 2020

I thought it would be in there after this comment 7 months ago discord/discord-api-docs#1160 (comment)

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 16, 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

No branches or pull requests

2 participants