I'm trying to create a temporary mute mand for my Discord bot. It creates the role muted, but the user can still write messages even though I've changed the perms. 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'm trying to create a temporary mute mand for my Discord bot. It creates the role muted, but the user can still write messages even though I've changed the perms. 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"
}
Share
Improve this question
edited Jun 28, 2023 at 19:12
A-Tech
1,1218 silver badges27 bronze badges
asked Mar 6, 2019 at 13:59
Andrej AcevskiAndrej Acevski
411 gold badge1 silver badge3 bronze badges
1
- This sounds more like a permissions issue than an issue with your bot. If you manually give the role in Discord, can the affected user still post? Important also to note that if you're testing it on - for example - yourself, it might appear not to work because server admins can always post. – Niet the Dark Absol Commented Mar 6, 2019 at 14:02
2 Answers
Reset to default 0I'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" }