📅  最后修改于: 2023-12-03 15:14:41.714000             🧑  作者: Mango
Discord.js DM is a module that allows you to send direct messages (DMs) to users on Discord through your bot using the Discord.js library. It's a simple yet powerful way to interact with your users privately.
To use Discord.js DM, you must first install Discord.js and then install this module by running the following command:
npm install discord.js-dm
Once installed, you can use the discord.js-dm
module by importing it into your code:
const dmd = require('discord.js-dm');
You can then send a DM to a user by calling the sendDM
function and passing in the user ID, your bot's client and the message you want to send.
dmd.sendDM(userID, botClient, message);
Here's an example:
const dmd = require('discord.js-dm');
const Discord = require('discord.js');
const client = new Discord.Client();
const token = 'YOUR BOT TOKEN';
client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}`);
});
client.on('message', msg => {
if (msg.content === '!send') {
const userID = 'USER ID HERE';
const message = 'Hello there!';
dmd.sendDM(userID, client, message);
}
});
client.login(token);
This will send a DM to the user with the given user ID containing the message "Hello there!".
Discord.js DM is a simple and easy-to-use module that adds a lot of value to your Discord bot. Whether you want to send important information to users privately or just want to spice up your bot's capabilities, this module is a great addition to your toolkit.