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

@discordtypesmodules/rest

v1.0.5

Published

An asynchonous rest client for the discord api used with discord.types

Downloads

8

Readme

@discordtypesmodules/rest

The rest librairie used with discordtypes.

How to install ?

npm i @discordtypesmodules/rest

How to configure ?

First, we will create a file that we will call index.js for example. Subsequently, we will have to import the @discordtypesmodules/rest library by writing

const {Rest} = require('@discordtypesmodules/rest')

Once this is done, we will be able to start configuring the rest module. We will write

//var rest corresponds to the variable that will define the rest module
var rest = new Rest({
  //RestOptions
});

You have different options in the Rest class, I invite you to look at the code to learn more. For rest to work, you will have to set the bot token with the function

rest.setToken('token')

Once all this is done, we will be able to send our first request. To do this:

//Rest.get will send a GET method with the requested route on the url passed in the api option on the Rest class options. By default the url is https://discord.com/api/v9
const firstRequest = async() => {
  console.log(await rest.get('/gateway/bot'))
}
firstRequest();

If you followed everything you should have code like this:

const {Rest} = require('@discordtypes/rest')

var rest = new Rest({
  //RestOptions
});
rest.setToken('token');
firstRequest = async() => {
  console.log(await rest.get('/gateway/bot'))
}
firstRequest();

How to use ?

REST

There are 5 api methods in the REST class.

  • GET
  • POST
  • PATCH
  • PUT
  • DELETE

GET

In the Rest class, the get function has 3 parameters: route is the route you want to execute the get request, options is an object with the RequestOptions and body is the request body. For example:

const get = async() => {
  console.log(await rest.get('/gateway/bot'))
}
get();

POST

In the Rest class, the post function has 3 parameters: route is the route you want to execute the post request, body is the request body and options is an object with the RequestOptions. For example :

//We trying to post a message to a channel
const post = async() => {
  await r.post('/channels/channnelid/messages', {
      "content": "Hello, World!",
      "tts": false,
      "embeds": [{
        "title": "Hello, Embed!",
        "description": "This is an embedded message."
      }]
    }
  )
}
post();

PUT

The put method is similar to the POST request.

rest.put('route', {
// body
}, {
// options
})

PATCH

The patch method is similar to the POST request

rest.patch('route', {
// body
}, {
// options
});

DELETE

In the Rest class, the delete function has 2 parameters: route is the route you want to execute the post request and options is an object with the RequestOptions. For example:

//deleting a message
const delete = async() => {
  await rest.delete('/channels/channelid/messages/messageid')
}
delete();

An other example

const example = async() => {
  await r.post('/channels/936983645183442984/messages', {
      "content": "Hello, World!",
      "tts": false,
      "embeds": [{
        "title": "Hello, Embed!",
        "description": "This is an embedded message."
      }]
    }
  ).then((req) => setTimeout(async() => await r.delete(`/channels/936983645183442984/messages/${req.id}`), 15000))
}
example()

CDN

How to configure ?

The cdn class is accessible by using

var rest = new Rest()
var cdn = rest.cdn

You can configure base url of the cdn by using

const {CDN} = require ('@discordtypesmodules/rest')
var rest = new Rest({cdn: new CDN({baseUrl: 'baseUrl')})

How to use ?

All the methods of the cdn class are readble here the ImageURLOptions parameter is optional

Image URL Options

size: the size of the image you want (16 - 4096) extension: The extension you want to use (the basic allowed extensions: png, jpeg, webp, gif)

Exemples

Getting user avatar url

cdn.userAvatar(userId, userAvatarHash, ImageURLOptions)

Getting user banner url

cdn.userBanner(userId, userBannerHash, ImageURLOptions)

Getting guild banner url

cdn.guildBanner(guildId, guildBannerHash, ImageURLOptions)

Contact ME

Discord: Nerzox#0001