偶然的你
2022-06-16 16:55:03
我已經在 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}) } }});
3 回答

慕俠2389804
TA貢獻1719條經驗 獲得超6個贊
最終代碼如下所示:
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 + '> !!');
}
}

心有法竹
TA貢獻1866條經驗 獲得超5個贊
我認為是用戶mention數組。所以你可以這樣做:
for (const user of mention) {
message.channel.send('YUB NUB!! YUB NUB!! Grrrrr!! @' + user.username)
}

一只萌萌小番薯
TA貢獻1795條經驗 獲得超7個贊
嘗試 :
const mention = message.mentions.users.first();
資料來源:https ://anidiots.guide/first-bot/command-with-arguments#grabbing-mentions
添加回答
舉報
0/150
提交
取消