【问题标题】:Detect role mention discord.js检测角色提及 discord.js
【发布时间】:2021-04-21 09:01:57
【问题描述】:

所以,我有一个命令可以阻止@everyone 角色向频道发送消息。我想让用户可以运行该命令并连同它一起提及一个特定的角色,然后该角色的成员将被阻止发送消息。 到目前为止,这是我的代码,它只锁定了所有人的角色:

if (!message.guild.me.hasPermission(`MANAGE_CHANNELS`)) return message.reply('I lack the required permissions to run this command. (Required Permissions: ``MANAGE_CHANNELS``)');          
        if(message.member.hasPermission("MANAGE_CHANNELS")){
            const channel = message.channel
            const Discord = require("discord.js")
            let replyMessage = message.reply("Are you sure you want to continue this command, it will remove send permissions from the everyone role. Type ``yes`` to continue.")
            let filter = msg => msg.author.id == message.author.id && msg.content.toLowerCase() == 'yes';
            message.channel.awaitMessages(filter, {max: 1, time: 20000}).then(collected => {
            
                message.reply('Confirmed!');

                message.channel.updateOverwrite(message.guild.everyone, {
                SEND_MESSAGES: false
                })
                .then(channel => channel.send("Channel Locked"))
                .catch(console.error);
            });


我在检查角色提及方面找不到太多信息,但我有这个,想知道您是否可以更改 message.mentions.**members**.first() 并将其替换为 message.mentions.**roles**.first()

let member = message.mentions.members.first() || message.guild.members.cache.get(args[0])

并且想知道是否有人可以帮助我。 谢谢。

【问题讨论】:

    标签: node.js discord discord.js


    【解决方案1】:

    是的,你可以替换

    message.mentions.users.first()
    

    message.mentions.roles.first()
    

    看起来像这样:

    let role = message.mentions.roles.first() || message.guild.roles.cache.find(role => role.name === args.join(" ");
    

    【讨论】:

      猜你喜欢
      • 2021-08-02
      • 2020-03-04
      • 2017-08-25
      • 2020-09-11
      • 2020-10-06
      • 1970-01-01
      • 1970-01-01
      • 2020-12-21
      • 2020-12-27
      相关资源
      最近更新 更多