Discord.js 机器人,临时静音命令不会静音
Posted
技术标签:
【中文标题】Discord.js 机器人,临时静音命令不会静音【英文标题】:Discord.js bot, temporary mute command doesn't mute 【发布时间】:2019-07-28 05:20:50 【问题描述】:如前所述。我正在尝试为我的 Discord 机器人创建一个临时静音命令。我遇到的问题是它创建了静音角色,但即使我更改了权限,用户仍然可以写消息。 最重要的是,我收到以下弃用警告:
(node:15956) DeprecationWarning: Collection#find: 传递函数 而是
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"
【问题讨论】:
这听起来更像是权限问题,而不是您的机器人问题。如果您在 Discord 中手动赋予角色,受影响的用户还能发帖吗?还需要注意的是,如果您在测试它 - 例如 - 您自己,它可能看起来不起作用,因为服务器管理员可以随时发布。 【参考方案1】:我在你的脚本中发现了一些错误,所以我为你修复了它
//!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"
【讨论】:
【参考方案2】:我发现了问题,就像你说的那样,是权限问题。最重要的是我应该改变:
let muterole = message.guild.roles.find(`name`, "muted");
致以下:
let muterole = message.guild.roles.find(muterole => muterole.name === "muted");
【讨论】:
以上是关于Discord.js 机器人,临时静音命令不会静音的主要内容,如果未能解决你的问题,请参考以下文章
Discord.js:GuildMember 的 setMute 命令不起作用?
使用 Discord.js 使用 Discord Bot 将语音频道中的所有人静音
当我尝试创建一个角色时,它给了我一个错误(discord.js)
Discord.js:message.guild.channels.forEach 不是函数