Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@discordjs/rest

Package Overview
Dependencies
Maintainers
2
Versions
1182
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@discordjs/rest

The REST API for discord.js

  • 2.4.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
204K
increased by3.34%
Maintainers
2
Weekly downloads
 
Created

What is @discordjs/rest?

@discordjs/rest is a powerful library designed to facilitate interactions with the Discord API. It provides a streamlined way to make REST API requests to Discord, making it easier to build and manage Discord bots and applications.

What are @discordjs/rest's main functionalities?

Making REST API Requests

This feature allows you to make REST API requests to Discord. In this example, it fetches the bot's user information using the 'get' method.

const { REST } = require('@discordjs/rest');
const { Routes } = require('discord-api-types/v9');
const rest = new REST({ version: '9' }).setToken('YOUR_BOT_TOKEN');

(async () => {
  try {
    const data = await rest.get(Routes.user('@me'));
    console.log(data);
  } catch (error) {
    console.error(error);
  }
})();

Handling Rate Limits

This feature helps in handling rate limits imposed by the Discord API. The example demonstrates how to listen for rate limit events and log the time to reset.

const { REST } = require('@discordjs/rest');
const { Routes } = require('discord-api-types/v9');
const rest = new REST({ version: '9' }).setToken('YOUR_BOT_TOKEN');

rest.on('rateLimited', (info) => {
  console.log(`Rate limited: ${info.timeToReset}ms`);
});

(async () => {
  try {
    const data = await rest.get(Routes.user('@me'));
    console.log(data);
  } catch (error) {
    console.error(error);
  }
})();

Posting Data

This feature allows you to post data to Discord. The example shows how to send a message to a specific channel using the 'post' method.

const { REST } = require('@discordjs/rest');
const { Routes } = require('discord-api-types/v9');
const rest = new REST({ version: '9' }).setToken('YOUR_BOT_TOKEN');

(async () => {
  try {
    const data = await rest.post(Routes.channelMessages('CHANNEL_ID'), { body: { content: 'Hello, world!' } });
    console.log(data);
  } catch (error) {
    console.error(error);
  }
})();

Other packages similar to @discordjs/rest

Keywords

FAQs

Package last updated on 02 Sep 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc