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

discordimageuploader

v0.1.3

Published

Upload images to Discord

Downloads

8

Readme

DiscordImageUploader

Upload images to Discord using the Discord API. This is a simple node.js module that allows you to upload images to Discord using their API. This module is useful for Discord bot developers who wish to upload images to Discord using their bot. This module is also useful for people who wish to upload images to Discord without using their web browser.

Installation

npm i discordimageuploader

Usage

When you instantiate a new DiscordImageUploader, it requires a token. This can be a user token or a bot token. If you don't know how to get a token, look it up on Google. I'm not going to explain it here. You can also pass in a boolean value to the constructor to tell it whether or not to wait for the upload to finish before moving on to the next job. If you set this to false, you can upload many files very quickly, but at the risk of getting rate limited or banned. The default is true. You can also pass in a number to tell it how long to wait between jobs if waitForUpload is set to true. This is in seconds. The default is 1 second.

const DiscordImageUploader = require('discordimageuploader');


/**
 * @param {string} token - The Discord token to use. 
 * @param {boolean} waitForUpload - Whether or not to wait for the upload to finish before moving on to the next job. If set to false, you can upload many files very quickly, but at the risk of getting rate limited or banned. Default is true.
 * @param {number} waitTime - How long to wait between jobs if waitForUpload is set to true. This is in seconds. Default is 1 second.
 */
let uploader = DiscordImageUploader("YOUR_DISCORD_TOKEN_HERE", waitForUpload = true, waitTime = 1);

let jobInitObj = uploader.uploadFile("test.jpg", "1159893559839830090", "Test message");
// jobInitObj is an object that contains the jobID and the promise.
// {promise: Promise, jobID: number}

jobInitObj.promise.then((url) => {
    console.log("Upload Complete!");
    console.log("URL: ", url);
    console.log("jobID: ", jobInitObj.jobID);
}).catch((e) => {
    console.log("Error: ", e);
});

let job = getJob(jobInitObj.jobID); // Returns the job object with the specified jobID.
// job is an object that contains the status, jobID, file name, channel ID, message, and URL (if the file was successfully uploaded).
console.log({job});

Example

This example will upload 1 image to Discord 10 times. It's basically the same as the code above.

const fs = require('fs');

const DiscordImageUploader = require("DiscordImageUploader");

uploader = new DiscordImageUploader("YOUR_DISCORD_TOKEN_HERE");

// This example will upload 1 image to Discord 10 times.
const doStuff = async () => {
    for (let i = 1; i <= 10; i++) {
        let jobInitObj = uploader.uploadFile("test.jpg", "1159893559839830090", "Test message" + i);

        jobInitObj.promise.then((url) => {
            console.log("Upload Complete!");
            console.log("URL: ", url);
            console.log("jobID: ", jobInitObj.jobID);
        }).catch((e) => {
            console.log("Error: ", e);
        });
    }
};

doStuff();
while(true) {}

License

GPL-3.0 License - Look up the license on the GNU website.

My take on it is this: if you use, modify or redistribute this code, you must make your code open source and you must give credit to me. Don't steal it. Don't be a jerk.

Contributing

If you wish to contribute to this project, feel free to make a pull request. I'm not much of a programmer, so if you see something that can be improved, please let me know. I'm always open to suggestions. Feel free to submit an issue if you find a bug or if you have a suggestion.