Reputation: 9
i have been designing my bot for 2-3 week. i have make the discord bot DM command through i can send message to anyone who is member of our server .. but how to read what they reply to that bot
Upvotes: 1
Views: 4441
Reputation: 6645
You get the messages in DMs the same as you get normal messages, using the "message" event. To see if the message was sent in DMs check if message.guild exists. For example:
if (!message.guild) {return console.log(`New Message in DMs: ${message.content}`)}
According to your comment, "i want to see that message in a specific channel and with their names
", you have to check the Channel ID. You can get the message author name by using Message's Author Property.
Here's an example:
const Discord = require("discord.js");
const Client = new Discord.Client();
Client.on("message", (message) => {
if (message.author.bot) return false; // If the message is sent by a bot, we ignore it.
if (message.channel.id == "661567766444376085") { // Checking if the message is sent in a certain channel.
let Channel = message.client.channels.get("661567766444376085"); // Getting the channel object.
console.log(`New message in #${Channel.name} from ${message.author.tag}: ${message.content}`);
};
});
Client.login("TOKEN");
The output should be: New message in #channel_name from Author#0000: Message Content!
.
Upvotes: 1
Reputation: 2722
Discord does not have the built-in ability to communicate with users as a dialogue. In order to organize such a communication, there are several options. You can use the channel.fetchMessages
method, which will return all messages in the dialog as collection, but this is not very convenient. You can create a server and in this server create a channel for each user and send his messages there, and yours to him in dm. There are many implementation options, but all of them require serious study in order for this to work correctly.
Upvotes: 0
Reputation: 117
const Discord = require('discord.js');
const client = new Discord.Client();
client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}!`);
});
client.on('message', msg => {
if (msg.content === 'ping') { //read messages
msg.reply('pong');
}
});
client.login('token');
click here for official docs.
Upvotes: 0