Editing Channel Permissions Issue

const Discord = require(‘discord.js’);
const ms = require(“ms”);

module.exports = {
name: “mute”,
description: “Mute people”,
execute: async(bot, message, args) => {
let toMute = message.guild.member(message.mentions.users.first() || message.guild.members.cache.get(args[0]));
if(!toMute) return message.reply(‘It looks like you didnt specify the user!’);
let muterole = message.guild.roles.cache.find(r => r.name === ‘Muted’);
if(!muterole){
try{
muterole = await message.guild.roles.create({
name: “Muted”,
color: “#000000”,
permissions:
})
message.guild.channels.cache.forEach(async (channel, id) => {
await channel.overwritePermission(muterole, {
SEND_MESSAGES: false,
ADD_REACTIONS: false
});
});
}catch(e){
console.log(e.stack);
}
} return message.channel.send(‘Cannot create role!’)

let mutetime = args[1];
if(!mutetime) return message.reply('You didnt specify the time');

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

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

}
}

The error is that:
(node:10074) UnhandledPromiseRejectionWarning: TypeError: channel.overwritePermission is not a function

const Discord = require(‘discord.js’);
const ms = require(“ms”);

module.exports = {
name: “mute”,
description: “Mute people”,
execute: async(bot, message, args) => {
let toMute = message.guild.member(message.mentions.users.first() || message.guild.members.cache.get(args[0]));
if(!toMute) return message.reply(‘It looks like you didnt specify the user!’);
let muterole = message.guild.roles.cache.find(r => r.name === ‘Muted’);
if(!muterole){
try{
muterole = await message.guild.roles.create({
name: “Muted”,
color: “#000000”,
permissions:
})
message.guild.channels.cache.forEach(async (channel, id) => {
await channel.overwritePermission(muterole, {
SEND_MESSAGES: false,
ADD_REACTIONS: false
});
});
}catch(e){
console.log(e.stack);
}
} return message.channel.send(‘Cannot create role!’)

let mutetime = args[1];
if(!mutetime) return message.reply('You didnt specify the time');

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

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

If channel.overwritePermission is not a function, go look at the discord.js docs and look at the functions available to channel.

It still does not work :frowning:

You need to use channel.overwritePermissions() instead of channel.overwritePermission().

Now it doesn’t even say something in console, it just does not create the role.

Your quotation marks aren’t quotation marks, they’re Unicode marks. “These aren’t” quotes - note how they are curly.
"These are" - these are straight

1 Like