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

discord.js

Package Overview
Dependencies
Maintainers
3
Versions
1748
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

discord.js

A powerful library for interacting with the Discord API

  • 15.0.0-dev.1729080291-62fb9de9c
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
206K
decreased by-10.12%
Maintainers
3
Weekly downloads
 
Created

What is discord.js?

discord.js is a powerful Node.js module that allows you to interact with the Discord API very easily. It provides a comprehensive set of features to create bots and manage Discord servers.

What are discord.js's main functionalities?

Creating a Bot

This code demonstrates how to create a simple Discord bot using discord.js. The bot logs 'Ready!' to the console when it is successfully logged in and ready.

const { Client, GatewayIntentBits } = require('discord.js');
const client = new Client({ intents: [GatewayIntentBits.Guilds] });
client.once('ready', () => {
  console.log('Ready!');
});
client.login('your-token-goes-here');

Handling Messages

This code shows how to handle messages in a Discord server. When a user sends a message with the content '!ping', the bot responds with 'Pong!'.

client.on('messageCreate', message => {
  if (message.content === '!ping') {
    message.channel.send('Pong!');
  }
});

Managing Roles

This code demonstrates how to manage roles in a Discord server. When a user sends a message with the content '!addRole', the bot adds a role named 'NewRole' to the user.

client.on('messageCreate', async message => {
  if (message.content === '!addRole') {
    let role = message.guild.roles.cache.find(r => r.name === 'NewRole');
    if (role) {
      await message.member.roles.add(role);
      message.channel.send('Role added!');
    }
  }
});

Sending Embeds

This code shows how to send embedded messages in Discord. When a user sends a message with the content '!embed', the bot responds with a rich embed message.

const { MessageEmbed } = require('discord.js');
client.on('messageCreate', message => {
  if (message.content === '!embed') {
    const embed = new MessageEmbed()
      .setTitle('Sample Embed')
      .setDescription('This is an example of an embed message')
      .setColor(0xff0000);
    message.channel.send({ embeds: [embed] });
  }
});

Other packages similar to discord.js

Keywords

FAQs

Package last updated on 16 Oct 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