我为服务器制作了一个简单的报价机器人,但管理员只希望 mod+ 的人能够添加报价以避免垃圾邮件.我去了文档并做了所有事情,但我无法让它工作.这是我所拥有的:
I made a simple quote bot for a server, but the admin only wants mod+ people to be able to add quotes to avoid spam. I went to the documentation and did everything, but I can't get this to work. Here's what I have:
//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', '
' + arg);
message.channel.send("Quote added: " + arg);
arr.push(arg);
}
}
}
非常挑剔.有时,如果用户具有 mod 角色,它会起作用,但大多数时候它不会.如果我这样做了
It's very finicky. Sometimes it will work if the user has the mod role, most of the times it wont. If I do
console.log(message.memeber.roles.has(adminRole));
console.log(message.memeber.roles.has(modRole));
两者都将输出为 false,但会起作用吗?老实说,我现在不知道.
both will output to false, but will work? Honestly, I have no idea at this point.
discord.js api 已更新,由于 .exists() 已被弃用,因此有更好的方法.
The discord.js api has been updated and there is a better way since .exists() has been deprecated.
if (message.member.roles.cache.some(role => role.name === 'Whatever')) {}
这比 .find() 好,因为 .find() 返回角色对象(或未定义),然后将其转换为布尔值..some() 方法默认返回一个布尔值.
This is better than .find() because .find() returns the role object (or undefined) which is then converted into a boolean. The .some() method returns a boolean by default.
这篇关于查明某人是否有角色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
使用 discord.js 检测图像并响应Using discord.js to detect image and respond(使用 discord.js 检测图像并响应)
检查 Discord 服务器中是否存在用户 IDCheck if user ID exists in Discord server(检查 Discord 服务器中是否存在用户 ID)
公会成员添加不起作用(discordjs)Guild Member Add does not work (discordjs)(公会成员添加不起作用(discordjs))
使用 REPLIT 创建我的第一个机器人,但总是错误Creating my first bot using REPLIT but always error Discord.JS(使用 REPLIT 创建我的第一个机器人,但总是错误 Discord.JS)
如何为我的 Discord.js 机器人编写事件/命令处理程How do I code event/command handlers for my Discord.js bot?(如何为我的 Discord.js 机器人编写事件/命令处理程序?)
如何从 Discord.js 中的用户名中查找用户 ID?How to find a User ID from a Username in Discord.js?(如何从 Discord.js 中的用户名中查找用户 ID?)