繁体   English   中英

Discord js检查反应用户角色

[英]Discord js check reaction user role

我正在尝试通过对按钮做出反应来关闭票证。 但反应必须由“支持”角色给出。 我做不到。 在这一点上,reaction.message.member.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已经处理了。 请注意,这意味着您可以确保用户只能打开一张票。

暂无
暂无

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

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