gpt4 book ai didi

javascript - 查明是否有人有 Angular 色

转载 作者:数据小太阳 更新时间:2023-10-29 05:41:36 25 4
gpt4 key购买 nike

我为服务器制作了一个简单的报价机器人,但管理员只希望 mod+ 人员能够添加报价以避免垃圾邮件。我去了文档并做了所有事情,但我无法让它工作。这是我拥有的:

//other code
else if (command === "addquote" && arg) {
let adminRole = message.guild.roles.find("name", "Admin");
let modRole = message.guild.roles.find("name", "Mod");

if(message.member.roles.has(adminRole) || message.member.roles.has(modRole)){
const hasArr = arr.some((el) => {
return el.toLowerCase().replace(/\s/g, '') === arg.toLowerCase().replace(/\s/g, '');
});

if(hasArr){
message.channel.send(arg.replace(/\s+/g,' ').trim() + " is already a Quote");
} else {
fs.appendFileSync('./Quotes.txt', '\r\n' + arg);
message.channel.send("Quote added: " + arg);
arr.push(arg);
}
}
}

这是非常挑剔的。如果用户具有 mod Angular 色,有时它会起作用,但大多数时候它不会。如果我这样做

console.log(message.memeber.roles.has(adminRole));
console.log(message.memeber.roles.has(modRole));

两者都将输出为 false,但会起作用吗?老实说,我现在还不知道。

最佳答案

discord.js api 已更新,自从 .exists() 已被弃用后,有更好的方法。

if (message.member.roles.cache.some(role => role.name === 'Whatever')) {}

这比 .find() 更好,因为 .find() 返回 Angular 色对象(或未定义),然后将其转换为 bool 值。 .some() 方法默认返回一个 bool 值。

关于javascript - 查明是否有人有 Angular 色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45317305/

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