简体   繁体   English

制作带有反应的验证系统

[英]Making a verification system with reactions

I have spotted some posts regarding the same topic, but not the exact problem.我发现了一些关于同一主题的帖子,但不是确切的问题。 I have also referred to javascript discords, where they were unable to assist me with my problem.我还提到了 javascript discords,他们无法帮助我解决我的问题。

So to inform you, The purpose of this verification system is to make sure the user understood the rules and can proceed to have the rest of the discord unlocked after he adds a checkmark reaction.因此通知您,此验证系统的目的是确保用户理解规则,并在添加复选标记反应后继续解锁其余的不和谐。

I have made a bot that has the command |message and it works fine and all, but I then want the bot to react to its own message once sent, and then wait for a user to also add a reaction, which will trigger a function, in this case.我制作了一个具有命令 |message 的机器人,它运行良好,但我希望机器人在发送后对自己的消息做出反应,然后等待用户添加反应,这将触发一个功能, 在这种情况下。 Triggering the bot to send a PM to the user and giving him a rank.触发机器人向用户发送 PM 并给他一个排名。

The bot adds his reaction fine, and upon reacting from me as an example it sends me a PM, but in the PM between me and the bot, the bot reacts once again to his message.机器人添加了他的反应很好,并且以我为例,它向我发送了一个 PM,但是在我和机器人之间的 PM 中,机器人再次对他的消息做出反应。 And this might be because of the code checking if the message author is the bot.这可能是因为代码会检查消息作者是否是机器人。

I was told in the JS Discord that the messageReactionAdd function has a Message Property, however upon searching I couldn't find a way to implement this into my code.我在 JS Discord 中被告知 messageReactionAdd 函数有一个 Message 属性,但是在搜索时我找不到将其实现到我的代码中的方法。 How would I do so?我该怎么做? Also trying to give the user a rank also spits out an error, and I am simply stuck between understanding and making stuff work.同样试图给用户一个排名也会吐出一个错误,我只是被困在理解和使东西工作之间。 I am getting confused with my own code, and I have minimal understanding of what I am doing, so with that said, Can anyone assist me doing this change, so I can get it in my head?我对自己的代码感到困惑,而且我对自己在做什么的了解很少,所以说,有人可以帮助我进行此更改,以便我可以将其记在脑海中吗? Giving me links to the discord.js documentation is just making me more confused, and the only way for me to learn is by creating, and successfully making it work.给我 discord.js 文档的链接只会让我更加困惑,我学习的唯一方法是通过创建并成功使其工作。 Any help is appreciated of course.任何帮助当然表示赞赏。

So, here is the code for the messageReactionAdd:所以,这里是 messageReactionAdd 的代码:

bot.on('messageReactionAdd', (reaction, user) => {
  if(reaction.emoji.name === "✅") {
    if(user === bot.user) return;
    // if(bot.channel === "dm") return;
    // let role = bot.guild.roles.find("name", "C - Verified");
    // let role1 = bot.guild.roles.find("name", "C - Unverified");

    //if(user.roles.has(role.id));
    //await(user.addRole(role.id) && user.removeRole(role1.id));
    user.send("Thank you for being apart of the community! As a thanks for accepting the rules, you have been awarded the verified role!");
    return;
}
});

And here is the code for the react function itself:这是反应函数本身的代码:

513769507907567628 is the bots' ID. 513769507907567628 是机器人的 ID。

bot.on("message", async message => {
if(message.author.id != "513769507907567628") return;
message.react("✅");
});

So, if you have any input that'd be great!所以,如果你有任何意见,那就太好了! If you can join a Discord Call please message me, That'd be the easiest and quickest.如果您可以加入 Discord 通话,请给我留言,那将是最简单快捷的方式。

Regards, Marius.问候,马吕斯。

If your problem occured here:如果您的问题发生在这里:

  await(user.addRole(role.id) && user.removeRole(role1.id));

then it is because:那么是因为:

1) await only exists inside async functions. 1) await只存在于async函数中。

2) you cannot just chain promises with && , a && b will result in b and that gets then awaited, so in your case you only wait for the removal. 2)你不能只用&&链接承诺, a && b将导致b然后等待,所以在你的情况下你只等待删除。


 bot.on('messageReactionAdd', async (reaction, user) => {
   if(reaction.emoji.name === "✅") return;
   if(user === bot.user) return;

   let role = bot.guild.roles.find("name", "C - Verified");
   let role1 = bot.guild.roles.find("name", "C - Unverified");

   await user.addRole(role.id);
   await user.removeRole(role1.id);
 });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM