I am starting with a new Discord bot using discord.js . I am still learning things but am curious if it is possible to send a reply to only the initiator, not the channel.
Channel.send
and message.reply
are both public to all.
const discord = require('discord.js');
const client = new discord.Client;
const prefix = '!';
client.once('ready', () => {
console.log('Ready!');
});
client.on('message', message => {
if (message.content === 'ping') {
message.channel.send('Pong!');
}
});
You can do:
message.author.send("text to send")
To send a direct private message
To dm the person who said the message do
message.author.send("hullo");
To send it to someone else,
let user = client.users.cache.get(`PUT-YOUR-ID-HERE`);
user.send("hullo");
There are 3 ways to respond to a user and i'll explain all three of them. To reply to the user (author) only, you might want to use .reply()
method. And this is how you use it:
message.reply("I replied to you :)!");
To send a message to the author in private only, you want to use the author.send()
method. This will start a private conversation in direct messages and only your bot and the author will be in this conversation.
message.author.send("This is a private conversation, nobody will ever know about.");
Just to send a message in the channel, use channel.send()
.
message.channel.send("This is a regular message, no user is pinged.");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.