discord.js | powerful JavaScript library | Bot library
kandi X-RAY | discord.js Summary
kandi X-RAY | discord.js Summary
discord.js is a powerful Node.js module that allows you to easily interact with the Discord API.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Attach recorder to audio .
- Create an error .
- Creates a new connection to the channel .
- Format an error message .
- Create an Enum .
- Register a message .
discord.js Key Features
discord.js Examples and Code Snippets
const Discord = require("discord.js"); //Подключаем discord.js для дальнейшего использования.
const client = new Discord.Client();
client.login("token"); //Где token пишем токен бота.
node название-файла-с-кодом.js
node название-файла-с-кодом.js
p
Node v12.16.1
NPM 6.13.4
Linux-based system
Node v12.16.1
NPM 6.13.4
Ubuntu 18.04 Server
Just make an account here : https://account.mongodb.com/
and get the URI to connect
* Connect to your machine
* Install Node and NPM
* Put the foll
const { Client, Message } = require('discord.js');
/**
* @param {Client} client - Discord.js Client.
* @param {Message} message - Discord.js Message.
* @param {Array} args - Array with parsed args.
*/
module.exports.run = async (client, message,
const {
SlashCommandBuilder
} = require('@discordjs/builders')
module.exports = {
data: new SlashCommandBuilder()
.setName('newsletter')
.setDescription('Send a message to members by role')
.addRoleOption(o
const {
MessageEmbed
} = require('discord.js')
module.exports = {
name: "rules",
description: "Post rules",
run: async (client, interaction) => {
// build the message
const embed = new MessageEmbed()
const { SlashCommandBuilder } = require('@discordjs/builders');
const data = new SlashCommandBuilder()
.setName('gif')
.setDescription('Sends a random gif!')
.addStringOption(option =>
option.setName('category')
import { Client, Intents } from 'discord.js'
import dotenv from 'dotenv'
dotenv.config()
const client = new Client({
intents: [
Intents.FLAGS.GUILDS,
Intents.FLAGS.GUILD_MESSAGES
]
})
client.on('ready', () => {
const ms = require('ms');
const { MessageEmbed } = require('discord.js')
module.exports = {
name: 'giveaway',
description: 'start a giveaway',
async execute(client, message, cmd, args, Discord){
let author = message.author.us
client.on('messageCreate', async (message) => {
if (message.content.toLocaleLowerCase() === prefix + 'join') { //Here's how to join a voice channel
if (!message.member.voice.channel) return message.channel.send('You need
const { Client, Intents } = require('discord.js')
const DiscordStream = require('@discordjs/voice')
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES, Intents.FLAGS.DIRECT_MESSAGES, Intents.FLAGS.GUI
Community Discussions
Trending Discussions on discord.js
QUESTION
I'm trying to create a discord bot, specifically the wedding team.
I am using a MongoDB database. Now everything works and is saved, but there is one problem, the data is saved for the second and third rounds, etc.
That is, the checks that I added do not work. I am trying to find data through const exists = Marry.findOne({ message.author.id });
, everything finds, I checked with console log.
But when I try to validate it just doesn't work. if (exists == message.author.id) { return message.channel.send("You are already married!"); }
What could be the problem? Help me please!
Maybe instead userID: message.author.id
i just need to find for the value message.author.id
. Is it possible?
ANSWER
Answered 2022-Mar-31 at 16:07So I think you're having an async issue in your code. The query itself should work just fined. However, I suggest you move exists and married outside of run. Maybe paste them under the MongoDB connection and find a way to pass the message.
QUESTION
It's my first time seeing this feature from a Discord bot. I tried looking everywhere but it seems that I have failed. There's this feature from Captcha.bot Discord bot where you can accept input from a pop-up window inside Discord.
There's a button in an embedded message made by Captcha.bot where you will have to answer a Captcha test. After pressing the button, it creates a pop-up window like this.
After placing the right answer on the captcha bot, here's the aftermath of the experience.
All I want to learn is how to summon that pop-up window using Discord.js if it's even possible or at least learn how they did it.
...ANSWER
Answered 2022-Mar-30 at 07:12Those are called modals, and they will be available in the next discord.js version, v14. There is already a pull request for this.
In the meantime, you can use an npm package like discord-modals or discordjs-modal.
You can find a working example with the discord-modals
package below. Don't forget to install it first using npm i discord-modals
.
QUESTION
I'm trying to write a discord bot.
Now there is one command in which another user is selected. So far, all commands work except for one, checking for the existence of a user.
That's how I do it:
...ANSWER
Answered 2022-Mar-27 at 15:33It looks like you are running the database query before checking if userToMarry
exists. You might want to change it as seen below. Additionally you may want to wrap query in a try/catch in case userToMarry
exists but is invalid.
QUESTION
I'm trying to create a bot for a discord server. I added the "marry" command to it.
When a user makes an offer, an announcement message appears. I've added two reactions to this post.
Now you can answer the offer by writing yes or no.
But I want to make it possible to answer the offer by clicking on the reaction, the first reaction is yes, the second is no. Will it be hard to do?
I did everything as in the documentation https://discordjs.guide/popular-topics/reactions.html#awaiting-reactions
But my bot does not react in any way to clicking reactions, please help..
...ANSWER
Answered 2022-Mar-25 at 20:36Try like this
QUESTION
I started learning about discord.js but now I am facing this issue. I tried some googling but couldn't manage to fix it.
...ANSWER
Answered 2021-Aug-07 at 16:34You need to specify the events which you want your bot to receive using gateway intents.
Instead of
const client = new Discord.Client();
Use
const client = new Discord.Client({ intents: [Enter intents here] })
For example
const client = new Discord.Client({ intents: ["GUILDS", "GUILD_MESSAGES"] })
Here's another useful link: https://discord.com/developers/docs/topics/gateway
QUESTION
Sooo, hello to everyone who sees this, it's my first time posting anything on StackOverflow. Anyway, recently I started learning discord.js and I managed to create a small bot in v12 with automatically changing status. Here is the code:
...ANSWER
Answered 2022-Feb-24 at 14:17An example to target your desired role using RoleManager#get()
or RoleManager#find()
QUESTION
I'm trying to make a Discord bot that just says if someone is online on the game.
However I keep getting this message:
[ERR_REQUIRE_ESM]: require() of ES Module from not supported. Instead change the require of index.js in... to a dynamic import() which is available in all CommonJS modules.
This is my code:
...ANSWER
Answered 2021-Sep-07 at 06:38node-fetch
v3 recently stopped support for the require
way of importing it in favor of ES Modules. You'll need to use ESM imports now, like:
QUESTION
I try to detect in real-time whether each member is speaking or not on a voice channel using discord.js v13. In other words, I want to reproduce the green circle of discord in my application. However, I couldn't find a suitable code example or article. Could you give me some advice?
Edit:
Based on the advice, I was able to solve it. The example of Recorder BOT was useful. A code example is shown below.
...ANSWER
Answered 2022-Jan-19 at 15:19Searching for this seems to suggest this used to be possible but was famously broken, because the event wouldn't fire, or would fire only once.
The client.voiceStateUpdate event used to give you a VoiceState that had a speaking property, which would tell you if someone was speaking (which seems like it never really worked).
The current discord.js documentation for VoiceState shows this property no longer exists, and you cannot do what you're asking using discord.js alone.
Edit: as per MrMythical's comment below, discord.js/voice has voiceRecievers, which exposes voiceReciever.speakingMap.users, a map of users currently speaking. you may get events for it by registering a listener.
QUESTION
I'm using the Tenor API to display a random gif in an embed in Discord.js. I did everything correctly, however, the image is not loading.
Here is my code:
...ANSWER
Answered 2022-Jan-14 at 07:34It's because itemurl
is not a direct link to the file, but the full URL to view the post on tenor.com. You should use the media
key instead. It's an array of dictionaries with the format (like gif
, mp4
, webm
, etc.) as the key and a media object (with keys like size
, duration
, and url
) as the value. It means you can get the URL of the gif image by using results[].media[0].gif.url
.
I've updated your code, it works as expected now:
QUESTION
Currently, my bot sends a file before the embed, but I want it the opposite way. This is my discord.js v12 code:
...ANSWER
Answered 2022-Jan-09 at 19:05.send()
is a promise, meaning that you can use .then()
functions after your message is sent. For example, your code would look something like this:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install discord.js
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page