- This package uses MongoDB to store the user ID and DM channel ID created by the Discord bot.
When a Discord bot creates a DM channel connection with a Discord user the channel ID created is unlikely to expire, meaning if we store this channel ID the bot doesn't have to waste a request to Discord and risk the bot getting locked out of creating new DM channels with users.
This package will automatically create and store the DM channel IDs for users when trying to send a user a message.
const { DMManager } = require(`@elara-services/dms`);
const dms = new DMManager("DISCORD_BOT_TOKEN_HERE", { url: `MONGODB_CONNECTION_URI_HERE` });
// OR
const { MongoClient } = require("mongodb");
const client = new MongoClient("xxxx");
const dms = new DMManager("DISCORD_BOT_TOKEN_HERE", client); // If you want to use an already active/created MongoClient instance.
dms.send({ // The APIMessage will be returned
user_id: `xxx`, // The Discord user's ID
body: { // The message send options.
content: `test`,
// Supports embeds, components, etc.
},
files: [], // Send optional files as well,
});