不和谐.js |如何获取用户的输入并为其发送消息?



所以我试图用javascript制作一个Discord机器人,但我试图制作它,这样它就可以获得用户的输入,而且它必须是一个人或类似的提及,并将其作为一条消息。

所以,如果我键入!say @Dobie,机器人会这样说@Dobie is a son of a cookie,请帮助我,这将非常有帮助。

这很容易实现。您必须检查消息(Message.mentions(中是否有任何提及,如果是这样,您可以向频道发回回复。

这里有一个例子:


client.on('message', (message) => {
// Making sure that the author of the message is not a bot.
if (message.author.bot) return false;
// Checking if the message's content starts with "!say"
if (message.content.toLowerCase().startsWith('!say')) {
// Making sure that there is at least one GuildMember mention within the message.
if (!message.mentions.members.size) return false;
// Sending the message.
message.channel.send(
`${message.mentions.members.first()} is a son of a cookie`
);
}
});

最新更新