gpt4 book ai didi

javascript - Discord.js 机器人,临时静音命令不会静音

转载 作者:行者123 更新时间:2023-12-05 07:25:07 24 4
gpt4 key购买 nike

如前所述。我正在尝试为我的 Discord 机器人创建一个临时静音命令。我遇到的问题是它创建了静音 Angular 色,但即使我更改了权限,用户仍然可以写消息。最重要的是,我收到以下弃用警告:

(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"
}

最佳答案

我发现了问题,正如您所说,是权限问题。最重要的是我应该改变:

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

以下内容:

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

关于javascript - Discord.js 机器人,临时静音命令不会静音,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55024871/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com