[英]Discord.js awaitReactions or on messageReactionAdd in private message
I've created a system which allows users to send a poll in a channel and want to give them extra options in a private message.我创建了一个系统,它允许用户在频道中发送投票,并希望在私人消息中为他们提供额外的选项。 For this, I'm trying to toggle a poll option when the user reacts to this private message with an emoji.
为此,当用户使用表情符号对此私人消息做出反应时,我尝试切换投票选项。 The server part works perfectly fine, but I can't get the private message reactions to work as intended.
服务器部分工作得很好,但我无法让私人消息反应按预期工作。
In summary: I'm trying to do something when the user reacts to a private message with an emoji.总结:当用户对带有表情符号的私人消息做出反应时,我正在尝试做一些事情。 I've got this working perfectly fine for server channels.
对于服务器频道,我已经完全正常工作了。
To test this I've tried the following:为了测试这一点,我尝试了以下方法:
This first one doesn't seem to get called with private messages.第一个似乎没有被私人消息调用。
client.on('messageReactionAdd', (reaction, user) => {
console.log("added response");
});
client.on('messageReactionRemove', (reaction, user) => {
console.log("removed response");
});
This second one is test code that runs in response to the "!beep" command.第二个是响应“!beep”命令而运行的测试代码。 Yet shows a few problems:
然而显示出一些问题:
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: I want to give a poll config panel to a user in a private message, that allows said user to toggle an option by clicking on a reaction to said config panel. TLDR:我想在私人消息中向用户提供一个轮询配置面板,允许所述用户通过单击对所述配置面板的反应来切换选项。
The stuff I tried didn't work.我试过的东西没有用。 Am I doing something wrong?
难道我做错了什么? Is there some other way to do this?
有没有其他方法可以做到这一点? Or is this simply not possible?
或者这根本不可能?
After debugging a bit more I found the problem, so in case anyone runs into an issue here;经过更多调试后,我发现了问题,以防万一有人在这里遇到问题;
These do work, I just had an if statement that got in my way XD.这些确实有效,我只是有一个 if 语句妨碍了我的方式 XD。
client.on('messageReactionAdd', (reaction, user) => {
console.log("added response");
});
client.on('messageReactionRemove', (reaction, user) => {
console.log("removed response");
});
In case they don't work, the message isn't cached.如果它们不起作用,则不会缓存消息。 For which the following give a good starting point (I haven't fully tried them though):
下面给出了一个很好的起点(虽然我还没有完全尝试过):
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.