R
R
rodgi2020-05-01 11:29:59
JavaScript
rodgi, 2020-05-01 11:29:59

The mute command does not work, what should I do?

I make the mute command:

const Discord = require("discord.js");
const ms = require("ms");
module.exports = {
    name: "mute",
    aliases: ["mut", "offchat", "chatoff"],
    description: "Mute user",
    usage: "<@mention, time, reason>",
    run: async (bot, message, args) => {// check if the command caller has permission to use the command
  //!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("Не могу найти пользователя.");
  if(tomute.hasPermission("KICK_MEMBERS")) return message.reply("Я не могу заглушить его!");
  const 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,
          SEND_TTS_MESSAGES: false,
          ATTACH_FILES: false,
          SPEAK: false
      });
    });
  }catch(e){
      console.log(e.stack);
  }
}
  //end of create role
  let mutetime = args[1];
  if(!mutetime) return message.reply("Укажите время!");

  await(tomute.addRole(muterole.id));
  message.reply(`<@${tomute.id}> успешно заглушен на ${ms(ms(mutetime))}`);

  setTimeout(function(){
    tomute.removeRole(muterole.id);
    message.channel.send(`<@${tomute.id}> был успешно разглушен!`);
}, ms(mutetime));
}};

Result: "message.guild.roles.find is not a function". I used to do the mute command in roughly the same way, but apparently everything has changed. I ask for help, thanks in advance for the answer (ready-made codes do not work on github either)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Neverov, 2020-05-01
@rodgi

The problem is that there is no find method on the message.guild.roles object, the console is not lying to you.
You need to use the .fetch() method and then iterate over to find the role you want.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question