Using discid

March 11, 2024

A few weeks ago, I made a command-line tool called discid. In a brief summary, it lets you check a user's Discord status using Lanyard.

Lanyard lets you expose your Discord presence and activities to a RESTful API. discid uses Lanyard to fetch users' statuses, and provides that information in a neat form in the command line.

To install discid, run this command in your terminal.

npm install -g discid

Getting Started

To find someone's user ID, run the following in the terminal, replacing userID with the 18-character ID of the user you want to check the status of:

discid <userID>

How do you find a user ID?

  1. Enable Developer Mode on Discord. You can do this by going to Discord settings, navigating to the Advanced tab, and enabling Developer Mode by checking the toggle.
  1. Right click on a user's profile picture and click on the option which says 'Copy User ID'. This will copy the user's ID to your clipboard.
  1. Go back to your command-line and run discid userID, replacing userID with the ID of the user you copied. For example, if you had the user ID 514106760299151372 copied, you would run:
discid 514106760299151372

Depending on what the status of the user is, different information may appear. For example, this is what it could look like.

iinter β€’ 🟒 Online
Listening To: It Ain't Hard to Tell by Nas on Illmatic β€’ 3min 14sec left
Playing: Visual Studio Code β€’ πŸ“‚ website  β€’ πŸ“ using-discid.md (51, 4) β€’ 44min 39sec
Platform: Desktop
Avatar URL: https://cdn.discordapp.com/avatars/514106760299151372/d14e90a16144987f53f5a3700aacc934.png
⚠️ Note: In order for the status to be found correctly, you need a user ID which is in the Lanyard Discord server: https://discord.gg/lanyard.

What else?

More fields are supported, not just the ones shown in the example. The full list that can be displayed is as follows:

  • Username
  • Status
  • Platform
  • Custom Status
  • Playing
  • Listening to Spotify
  • Streaming
  • Watching
  • Avatar URL

More specific details are also able to be shown for certain fields. For example, the time left on a song, activity/state details, and more.

Listening to: ζ˜₯色γƒͺップ by ε‘ŠRADIO on KAGUYA ULTRA BEST β€’ 2min 50sec left
# time left is calculated by subtracting the current time from the end time. song name, artist, and album comes from other fields set in the 'activities' section.

Playing: osu! β€’ Goose house - Hikaru nara [Synesthesia] β€’ Clicking circles
# ie. 'Goose house - Hikaru Nara [Synthesis]' comes from the state details, which is set to that text.

Options


--json

This option will print the user's information in a formatted JSON response. You can see an example of this with user ID 514106760299151372 below.

{
  "kv": {
    "email": "hi@iinter.me",
    "location": "UK",
    "website": "https://iinter.me"
  },
  "spotify": {
    "track_id": "03yMZBtC3QxyK7ttlBLeme",
    "timestamps": {
      "start": 1713979964806,
      "end": 1713980148219
    },
    "album": "THE MOUSE & THE MASK",
    "album_art_url": "https://i.scdn.co/image/ab67616d0000b2736c3fb85147fcf2972923cf2d",    
    "artist": "DANGERDOOM; MF DOOM; Danger Mouse",
    "song": "A.T.H.F. (Aqua Teen Hunger Force)"
  },
  "discord_user": {
    "id": "514106760299151372",
    "username": "iinter",
    "avatar": "d14e90a16144987f53f5a3700aacc934",
    "discriminator": "0",
    "bot": false,
    "clan": null,
    "global_name": "lunar",
    "avatar_decoration_data": null,
    "display_name": "lunar",
    "public_flags": 128
  },
  "activities": [
    {
      "id": "98c669cfc69b645",
      "name": "osu!",
      "type": 0,
      "state": "Idle",
      "application_id": "367827983903490050",
      "assets": {
        "large_image": "373344233077211136",
        "large_text": "intter",
        "small_image": "373370493127884800",
        "small_text": "osu!"
      },
      "created_at": 1713979992340
    },
    {
      "flags": 48,
      "id": "spotify:1",
      "name": "Spotify",
      "type": 2,
      "state": "DANGERDOOM; MF DOOM; Danger Mouse",
      "session_id": "aff3a5a656181f92d4ecbbe49952a167",
      "details": "A.T.H.F. (Aqua Teen Hunger Force)",
      "timestamps": {
        "start": 1713979964806,
        "end": 1713980148219
      },
      "assets": {
        "large_image": "spotify:ab67616d0000b2736c3fb85147fcf2972923cf2d",
        "large_text": "THE MOUSE & THE MASK"
      },
      "sync_id": "03yMZBtC3QxyK7ttlBLeme",
      "created_at": 1713979984161,
      "party": {
        "id": "spotify:514106760299151372"
      }
    }
  ],
  "discord_status": "online",
  "active_on_discord_web": false,
  "active_on_discord_desktop": true,
  "active_on_discord_mobile": false,
  "listening_to_spotify": true
}

--open

This option will open the user's Discord profile in your web browser. You can see an example of this in action below:

--kv

Lanyard also has key-value pairs (KV for short) which allow a key-value store to be added to the response.

"When a KV pair is updated, a PRESENCE_UPDATE for the user will also be emitted through the Lanyard socket."

Here's an example with the KV of 514106760299151372:

{
  "kv": {
    "email": "hi@iinter.me",
    "location": "UK",
    "website": "https://iinter.me"
  },
  // rest of response...
}

To check this package and its source code out on GitHub, click here, and visit it on NPM here. If you'd also like to, star the repository!


This post was last updated on 24/04/2024 18:54.