[英]DiscortJS bot send a message back on the channel mentioning a specific user
我已经在 js 上构建了这个消息。 如果您将机器人标记为用户以添加消息+标记该人,我想添加一个条件,否则只是发送普通消息。
我遇到的问题是 user_mention 的正确变量是什么。 我找到了不同的方法,但无法使其工作。
DiscordClient.on('message', message => {
const msg = message.content.toLowerCase();
const mention = message.mentions.users;
if (msg === "yubnub") {
if (mention == null){
message.channel.send('YUB NUB!! YUB NUB!! Grrrrr!!');
} else {
message.channel.send('YUB NUB!! YUB NUB!! Grrrrr!! ' + ${@user_mention})
}
}
});
谢谢@boris 和@Adrian。 最终代码如下所示:
if (msg.startsWith("yubjub")) {
const mention = message.mentions.members;
if (mention.size === 0){
message.channel.send('YUB NUB!! YUB NUB!! Grrrrr!!);
} else {
const mentionUser = mention.first().user;
message.channel.send('YUB NUB!! YUB NUB!! Stab Stab Stab <@' + mentionUser.id + '> !!');
}
}
我认为mention
的是一组用户。 所以你可以这样做:
for (const user of mention) {
message.channel.send('YUB NUB!! YUB NUB!! Grrrrr!! @' + user.username)
}
尝试:
const mention = message.mentions.users.first();
资料来源: https://anidiots.guide/first-bot/command-with-arguments#grabbing-mentions
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.