[英]Discord bot only replying to initator
我从使用discord.js的新 Discord 机器人开始。 我仍在学习,但很好奇是否可以只向发起者而不是频道发送回复。
Channel.send
和message.reply
都是公开的。
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!');
}
});
你可以做:
message.author.send("text to send")
直接发送私信
给发消息的人发消息
message.author.send("hullo");
送给别人,
let user = client.users.cache.get(`PUT-YOUR-ID-HERE`);
user.send("hullo");
有 3 种方式来响应用户,我将解释所有这三种方式。 要仅回复用户(作者),您可能需要使用.reply()
方法。 这就是你如何使用它:
message.reply("I replied to you :)!");
要仅向作者私下发送消息,您需要使用author.send()
方法。 这将在直接消息中开始私人对话,并且只有您的机器人和作者将参与此对话。
message.author.send("This is a private conversation, nobody will ever know about.");
只是要在频道中发送消息,请使用channel.send()
。
message.channel.send("This is a regular message, no user is pinged.");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.