我已经在 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 + '> !!');
}
}
关于javascript - DiscortJS 机器人在 channel 上发回一条消息,提及特定用户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61055865/