我已经在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})
}
}
});
答案 0 :(得分:1)
谢谢@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 + '> !!');
}
}
答案 1 :(得分:0)
我认为mention
是users的数组。因此,您可以这样做:
for (const user of mention) {
message.channel.send('YUB NUB!! YUB NUB!! Grrrrr!! @' + user.username)
}
答案 2 :(得分:0)
尝试:
const mention = message.mentions.users.first();
来源:https://anidiots.guide/first-bot/command-with-arguments#grabbing-mentions