admin管理员组文章数量:1394133
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" }
本文标签: javascriptTemporary mute command doesn39t mute and throws deprecation warningStack Overflow
版权声明:本文标题:javascript - Temporary mute command doesn't mute and throws deprecation warning - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744679271a2619300.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论