npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

discord-self.js

v0.2.1

Published

A discord API/Gateway wrapper for user accounts

Downloads

11

Readme

About The Project

Automating discord is cumbersome when all the mature options seem to restrict access to user accounts. This prevents so many cool things from being able to work and I often found myself wanting to create these things so I decided to throw together a library that is fast and robust (hopefully).

Here are some use cases:

  • Auto responding to messages
  • Exporting your DM or guild messages.
  • Leaving all your guilds
  • Copying data you typically don't see
  • Downloading media
  • Auto filter your chat messages

The project is still fairly young so it's missing some vital features but for most it should suffice. If you need a particular feature implemented just create a feature request in the issues section.

Getting Started

To start using discord-self.js you will need to install it via npm or yarn. You will also need access to your discord token -> One of the methods

  • npm
    npm install discord-self.js
  • yarn
    yarn add discord-self.js

Usage and Examples

Using discord-self.js is simple, just provide it your token, initialize and login. After that, for most features, it won't matter if the websocket disconnects or not. Just request away.

  • Login and retrieve all DM messages (for exporting for example)
import { Discord } from 'discord-self.js';

(async () => {
    const discord = new Discord("DISCORD-TOKEN-HERE");

    // Login
    await discord.init();
    if (!await discord.login()) throw new Error("Cannot login");
    console.log("Logged in as " + discord.userTag);

    // Get all DM channels
    const channels = await discord.getDMChannels();
    console.log(`Found ${channels.length} DM channels`);

    // Get all messages from each channel
    for (const channel of channels) {
        const messages = await discord.getAllMessages(channel.id);
        console.log(`Found ${messages.length} messages in channel ${channel.id}`);
    }
})();
  • Custom Emoji are parsed from content automatically
await discord.sendMessage("897219587714719748", ":balls_emoji:");
  • Save all your valuable information
import { Utils, Discord } from 'discord-self.js';
import fs from 'fs';

(async () => {
    const discord = new Discord("DISCORD-TOKEN-HERE");

    await discord.init();
    if (!await discord.login()) throw new Error("Cannot login");
    fs.writeFileSync("user.json", Utils.jsonFormat(Object.assign({}, discord.sessionInfo.user, { country_code: discord.sessionInfo.country_code })));
    fs.writeFileSync("user_settings.json", Utils.jsonFormat(discord.sessionInfo.user_settings));
    fs.writeFileSync("sessions.json", Utils.jsonFormat(discord.sessionInfo.sessions));
    fs.writeFileSync("relationships.json", Utils.jsonFormat(discord.sessionInfo.relationships));
    fs.writeFileSync("guilds.json", Utils.jsonFormat(discord.sessionInfo.guilds));
    fs.writeFileSync("connected_accounts.json", Utils.jsonFormat(discord.sessionInfo.connected_accounts));
    fs.writeFileSync("payment_sources.json", Utils.jsonFormat(await discord.getPaymentSources()));
    fs.writeFileSync("payments.json", Utils.jsonFormat(await discord.getPayments()));
})();
  • Wait for rate limits (this is something that needs a lot of work)
import { Utils } from 'discord-self.js';

// ... etc

// <any> should be the type the function returns (if you want types)
await Utils.waitIfRateLimited<any>(async () => {
    return await discord.deleteGuildRole(guild.id!, role.id!);
});

These are just a few examples but you can do most of the things a typical user can do and more.

Roadmap

Although I say it can do most things. There is still much to do

  • Add testing to keep things professional
  • Implement voice connection and streaming
  • Implement some method for gracefully handling rate limits
  • Cover most of the REST API
  • Possibly wrap the event emitter up and add type information instead of raw websocket events
  • Lazy guild loading. Super easy just need to find the time

Find somethings missing and it's not here? Open an issue and let me know what could be improved.

Contributing

Any contributions you can make are super appreciated.

If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Mwah!

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

License

Distributed under the MIT License. See LICENSE for more information.

Acknowledgments