不一致js检查反应用户角色 [英] Discord js check reaction user role

查看:23
本文介绍了不一致js检查反应用户角色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过对按钮做出反应来关闭票证。但反应必须由"支持"角色来给予。我做不到。在这一点上,reaction.Message.ember.Roles.Has对我没有帮助。以下是我的代码;

client.on("messageReactionAdd", (reaction, user) => {
  if(reaction.message.member.roles.has('ROLE')) {
  let id = user.id.toString().substr(0, 4) + user.discriminator;
  let chan = `ticket-${id}`;

  const supchan = reaction.message.guild.channels.find(
    (channel) => channel.name === chan
  );
  const chan_id = supchan ? supchan.id : null;

  if (
    reaction.emoji.name === "🔒" &&
    !user.bot &&
    user.id != "ID"
  ) {
    reaction.removeAll();

    const channel = client.channels.find("name", chan);
    const delMsg = new Discord.RichEmbed()
      .setColor("#E74C3C")
      .setDescription(`:boom: Ticket will be deleted in 5 seconds.`);

    channel.send(delMsg).then(() => {
      var counter = 0;

      const intervalObj = setInterval(() => {
        counter++;
        if (counter == 5) {
          const message = reaction.message;
          message.delete();

感谢您的帮助!

推荐答案

所有这些都包装在messageReactionAdd事件中

// Replace "message_id" with the proper message id
// Checks if it's the correct message
if (reaction.message.id == "message_id") {

     // Check if author of ticket message is from the same user who reacted
     if (reaction.message.author == user) {

          // Check correct emoji
          if (reaction.emoji.name == "🔒") {
               // Code to close ticket
          }

     }

}

编辑: 同样,它将被包装在messageReactionAdd事件中:

// Try to get the ticket message
// If there's none then the user was never opened a ticket so we simply return the code
const ticketMessage = client.tickets.get(user);
if (!ticketMessage) return;

// Checks if it's the correct message
if (reaction.message.id == ticketMessage.id) {

     // Check correct emoji
     if (reaction.emoji.name == "🔒") {
         // Code to close ticket
     }

}
我删除了检查反应消息作者的代码,因为获取ticketMessage已经处理了这个问题。请注意,这意味着您可以确保用户只能打开一个票证。

这篇关于不一致js检查反应用户角色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆