[英]Discord.js awaitReactions or on messageReactionAdd in private message
我創建了一個系統,它允許用戶在頻道中發送投票,並希望在私人消息中為他們提供額外的選項。 為此,當用戶使用表情符號對此私人消息做出反應時,我嘗試切換投票選項。 服務器部分工作得很好,但我無法讓私人消息反應按預期工作。
總結:當用戶對帶有表情符號的私人消息做出反應時,我正在嘗試做一些事情。 對於服務器頻道,我已經完全正常工作了。
為了測試這一點,我嘗試了以下方法:
第一個似乎沒有被私人消息調用。
client.on('messageReactionAdd', (reaction, user) => {
console.log("added response");
});
client.on('messageReactionRemove', (reaction, user) => {
console.log("removed response");
});
第二個是響應“!beep”命令而運行的測試代碼。 然而顯示出一些問題:
const reactions = ["0️⃣", "1️⃣", "2️⃣", "3️⃣", "4️⃣", "5️⃣", "6️⃣", "7️⃣", "8️⃣", "9️⃣", "🔟"];
message.channel.send('@here Boop :robot:')
.then(async (sentMessage) => {
for (var i=0; i < reactions.length; i++) {
await sentMessage.react(reactions[i]);
}
/////////////// TEST CODE!!!!
const filter = (reaction, user) => {
console.log("filter called");
return true;
};
sentMessage.awaitReactions(filter, { time: 33000, errors: ['time'] })
.then(collected => {
console.log("collected");
const reaction = collected.first();
console.log(reaction.emoji);
})
.catch(collected => {
console.log("Time's up");
});
});;
TLDR:我想在私人消息中向用戶提供一個輪詢配置面板,允許所述用戶通過單擊對所述配置面板的反應來切換選項。
我試過的東西沒有用。 難道我做錯了什么? 有沒有其他方法可以做到這一點? 或者這根本不可能?
經過更多調試后,我發現了問題,以防萬一有人在這里遇到問題;
這些確實有效,我只是有一個 if 語句妨礙了我的方式 XD。
client.on('messageReactionAdd', (reaction, user) => {
console.log("added response");
});
client.on('messageReactionRemove', (reaction, user) => {
console.log("removed response");
});
如果它們不起作用,則不會緩存消息。 下面給出了一個很好的起點(雖然我還沒有完全嘗試過):
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.