Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/141.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Discord.js 代码无法编辑现有角色的PERM_Discord.js - Fatal编程技术网

Discord.js 代码无法编辑现有角色的PERM

Discord.js 代码无法编辑现有角色的PERM,discord.js,Discord.js,我正在尝试编写一个机器人程序,该程序编辑角色“LFT”的权限,并在提到该角色时使其可提及的权限false。但是,代码什么也不做。我刚刚收到一条弃用警告 如果有人能帮我,那就太好了 让lftrole=message.guild.roles.find(“name”,“LFT”); if(message.content.includes('@LFT')){ lftrole.edit({ 可提及:错误 }); log(`Role-indicatable:False`); .那么( 设置超时(()=>{

我正在尝试编写一个机器人程序,该程序编辑角色“LFT”的权限,并在提到该角色时使其可提及的权限
false
。但是,代码什么也不做。我刚刚收到一条
弃用警告

如果有人能帮我,那就太好了

让lftrole=message.guild.roles.find(“name”,“LFT”);
if(message.content.includes('@LFT')){
lftrole.edit({
可提及:错误
});
log(`Role-indicatable:False`);
.那么(
设置超时(()=>{
让lftrole=message.guild.roles.find(“name”,“LFT”);
lftrole.edit({
可提及:对
});
log(`Role-indentiable:True`);
}, 30000)
);
}

您的代码不起作用,因为您正在检查
消息。内容
是否包含
'@LFT'
:提到的内容呈现为
@RoleName
,但对于bot来说,它们看起来像

您可以尝试解析该模式,但使用它会更容易。我会这样做:

让lftrole=message.guild.roles.find(“name”,“LFT”);
函数changeRole(值=true){
lftrole.edit({
可提及:价值
});
log(`LFT角色可提及:${value}`);
}
if(message.indications.roles.has(lftrole.id)){
转换角色(假);
setTimeout(changeRole,30000);
}
注意:您得到的
DeprecationWarning
来自您用来查找角色的时间。不推荐使用的方法使您使用一个函数来返回一个元素是否可接受:通过这种方法,您可以组合更多的条件。以下是方法:

//而不是使用:
让role=guild.roles.find(“name”,“myRole”);
//您可以使用:
让role=guild.roles.find(r=>r.name==“myRole”);
//当您要检查多个内容时,这非常有用,
//或者如果您想使用代码中的其他变量
让role=guild.roles.find(r=>{
if(otherVariable)返回r.name==“myRole”;
否则返回r.name==“myRole”&&r.indicatable;
});

听到这个消息很高兴:)