[英]Discord.js | How to get user's input and make a message for it?
所以我正在尝试使用 javascript 制作一个 Discord 机器人,但我正在尝试制作它以便它可以获取用户的输入并且它必须是一个人或喜欢提及,并将其作为消息。
因此,如果我输入!say @Dobie
,机器人会说@Dobie is a son of a cookie
这样@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`
);
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.