简体   繁体   中英

Discord.js bot, temporary mute command doesn't mute

As stated. I'm trying to create a temporary mute command for my Discord bot. The problem I ran into is it creates the role muted but the user can still write messages even though I've changed the perms. And on top of that I'm getting the following deprecation warning:

(node:15956) DeprecationWarning: Collection#find: pass a function instead

    const Discord = require("discord.js");
const ms = require("ms");

module.exports.run = async (bot, message, args) => {

  //!tempmute @user 1s/m/h/d

  let tomute = message.guild.member(message.mentions.users.first() || message.guild.members.get(args[0]));
  if(!tomute) return message.reply("Couldn't find user.");
  if(tomute.hasPermission("MANAGE_MESSAGES")) return message.reply("Can't mute them!");
  let muterole = message.guild.roles.find(`name`, "muted");
  //start of create role
  if(!muterole){
    try{
      muterole = await message.guild.createRole({
        name: "muted",
        color: "#000000",
        permissions:[]
      })
      message.guild.channels.forEach(async (channel, id) => {
        await channel.overwritePermissions(muterole, {
          SEND_MESSAGES: false,
          ADD_REACTIONS: false
        });
      });
    }catch(e){
      console.log(e.stack);
    }
  }
  //end of create role
  let mutetime = args[1];
  if(!mutetime) return message.reply("You didn't specify a time!");

  await(tomute.addRole(muterole.id));
  message.reply(`<@${tomute.id}> has been muted for ${ms(ms(mutetime))}`);

  setTimeout(function(){
    tomute.removeRole(muterole.id);
    message.channel.send(`<@${tomute.id}> has been unmuted!`);
  }, ms(mutetime));


//end of module
}

module.exports.help = {
  name: "tempmute"
}

I've found the problem and like you said, it was the permissions. And on top of that I should have changed:

let muterole = message.guild.roles.find(`name`, "muted");

To the following:

let muterole = message.guild.roles.find(muterole => muterole.name === "muted");

I found some errors in your script so I fixed it back up for you

//!tempmute @user 1s/m/h/d

  let tomute = message.guild.member(message.mentions.users.first() ||
message.guild.members.get(args[0]));   if(!tomute) return
message.reply("Couldn't find user.");  
if(tomute.hasPermission("MANAGE_MESSAGES")) return
message.reply("Can't mute them!");   let muterole =
message.guild.roles.find(muterole => muterole.name === "muted");  
//start of create role   if(!muterole){
    try{
      muterole = await message.guild.createRole({
        name: "muted",
        color: "#000000",
        permissions:[]
      })
      message.guild.channels.forEach(async (channel, id) => {
        await channel.overwritePermissions(muterole, {
          SEND_MESSAGES: false,
          ADD_REACTIONS: false
        });
      });
    }catch(e){
      console.log(e.stack);
    }   }   //end of create role   let mutetime = args[1];   if(!mutetime) return message.reply("You didn't specify a time!");

  await(tomute.addRole(muterole.id));   message.reply(`<@${tomute.id}>
has been muted for ${message(message(mutetime))}`);

  setTimeout(function(){
    tomute.removeRole(muterole.id);
    message.channel.send(`<@${tomute.id}> has been unmuted!`);   }, message (mutetime));

//end of module }

module.exports.help = {   name: "tempmute" }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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