我有一个静音系统discord.js的疑问

发布于 2025-02-08 13:36:20 字数 767 浏览 2 评论 0原文

我的静音系统有问题。如果我发送+MUTE @member它不会发挥作用。

client.on('message', message => {
    if (message.content === "+mute") {
      if (!message.member.permissions.has("MANAGE_ROLES")) {
        return message.reply({content: `You need permissions to use command`})
        const mutedRole = message.guild.roles.cache.get('<986283559092359228>');
        if (!mutedRole)
          return message.reply('There is no Muted role on this server');
        const member = message.mentions.members.first();
        member.roles.add(role); 
        message.channel.send(member + 'has Been Muted');
      } else {
        message.channel.send("You didn't mention the user to mute!")
      }
    }
})

I have a problem with my mute system. If I send +mute @member it doesn't give a role.

client.on('message', message => {
    if (message.content === "+mute") {
      if (!message.member.permissions.has("MANAGE_ROLES")) {
        return message.reply({content: `You need permissions to use command`})
        const mutedRole = message.guild.roles.cache.get('<986283559092359228>');
        if (!mutedRole)
          return message.reply('There is no Muted role on this server');
        const member = message.mentions.members.first();
        member.roles.add(role); 
        message.channel.send(member + 'has Been Muted');
      } else {
        message.channel.send("You didn't mention the user to mute!")
      }
    }
})

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

黄昏下泛黄的笔记 2025-02-15 13:36:20

您将静音角色定义为mutedrole,但是当您赋予会员一个角色时 - 您使用角色不存在的角色,因此解决方案很简单,更改成员.roles.add(role); to member.roles.add(mutedRole);

You define your mute role as mutedRole, but when you give member a role - you use role, which doesn't exist, so solution is simple, change member.roles.add(role); to member.roles.add(mutedRole);

來不及說愛妳 2025-02-15 13:36:20

您只需要在定义muterole时写下角色ID,因此请将其更改

const mutedRole = message.guild.roles.cache.get('<986283559092359228>');

const mutedRole = message.guild.roles.cache.get('986283559092359228');

proam.Add() 中的相同名称mutedrole,然后使用try/try/捕获,因为机器人不能扮演高于其最高角色的角色,因此请尝试:

try {
    member.roles.add(mutedRole);
  } catch (err) {
           console.log(err)
           message.channel.send({content: `Role is higher than my highest role!`})
           } 

要添加,您

message.channel.send({content: `${member} has Been Muted`});

还需要检查用户是否已经具有mutedrole或不

You need to write only the role ID when defining muteRole, so change this

const mutedRole = message.guild.roles.cache.get('<986283559092359228>');

To this

const mutedRole = message.guild.roles.cache.get('986283559092359228');

Then use the same name mutedRole in role.add() and use try/catch because the bot cannot give a role that is higher than its highest role, so try:

try {
    member.roles.add(mutedRole);
  } catch (err) {
           console.log(err)
           message.channel.send({content: `Role is higher than my highest role!`})
           } 

Just to add, you can directly do

message.channel.send({content: `${member} has Been Muted`});

You also need to check if the user has the mutedRole already or not

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文