亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

DiscortJS 機器人在提及特定用戶的頻道上發回消息

DiscortJS 機器人在提及特定用戶的頻道上發回消息

偶然的你 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 + '> !!');


}

}


查看完整回答
反對 回復 2022-06-16
?
心有法竹

TA貢獻1866條經驗 獲得超5個贊

我認為是用戶mention數組。所以你可以這樣做:


for (const user of mention) {

    message.channel.send('YUB NUB!! YUB NUB!! Grrrrr!! @' + user.username)

}


查看完整回答
反對 回復 2022-06-16
?
一只萌萌小番薯

TA貢獻1795條經驗 獲得超7個贊

嘗試 :

const mention = message.mentions.users.first();

資料來源:https ://anidiots.guide/first-bot/command-with-arguments#grabbing-mentions


查看完整回答
反對 回復 2022-06-16
  • 3 回答
  • 0 關注
  • 166 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號