【发布时间】:2019-08-24 09:01:31
【问题描述】:
所以基本上,我已经选择了应该由哪个角色使用哪些命令,我已经创建了一些代码,但我的问题是,无论出于何种原因,如果用户对任何角色有任何要求命令,他们能够使用所有命令。我已经有一个多星期的问题了。它需要基于角色 ID,因为用户必须使用角色 ID 在数据库中设置允许的角色。
这是我的 Discord Bot,数据库是 Firebase,我在 VSC 上运行 Discord.JS/Node.JS。我已经尝试对其进行格式化,以便首先出现角色过滤器,但这变得非常混乱。我不认为问题是从数据库中引用角色,因为我已经在控制台中记录了请求的 ID,并且它返回了正确的字符串。此外,当用户没有任何允许的角色时,他们无法使用这些命令。
let msg_array = msg.content.split(" ");
let command = msg_array[0];
let args = msg_array.slice(1);
let prefix = "t!"
let inputtedCMD = msg.content.slice(prefix.length).split(" ")
let cmd = bot.commands.get(inputtedCMD[0])
let allowedR = null
await firebaseDB.collection('roles').doc(msg.guild.id).get('role_id').then((r) => {
if (!r.exists){
msg.channel.send("You havn't chosen an allowed admin role.")
} else {
allowedR = `${r.data().role_id}`;
}
})
let genRole = null
await firebaseDB.collection('generalRoles').doc(msg.guild.id).get('generalRole_id').then((h) => {
if (!h.exists){
msg.channel.send("You havn't chosen an allowed general role.")
} else {
genRole = `${h.data().generalRole_id}`;
}
})
let guildOwner = null
await firebaseDB.collection('guilds').doc(msg.guild.id).get('generalRole_id').then((q) => {
if (!q.exists){
msg.channel.send("Cannot access guild owner data.")
} else {
guildOwner = `${q.data().guildOwnerID}`;
}
})
let generalRole = msg.guild.roles.get(genRole)
let adminRole = msg.guild.roles.get(allowedR)
if (!command.startsWith(prefix)) return;
if (inputtedCMD === "databaseReset") {
if (guildOwner === msg.author.id || msg.author.id === "198590136684904448") {
cmd.run(bot, msg, args, firebaseDB).then(() => {
console.log("[COMMAND] User w/ permission ran '" + inputtedCMD + "'")
return;
})
} else {
const notAllowed = new Discord.RichEmbed()
.setAuthor("Hey, " + msg.author.tag, bot.user.displayAvatarURL)
.setDescription("**__No access__** \n *You need the required role to be able to use that command.*")
.setColor("#00A6ff")
.setTimestamp()
.setFooter("Ticket Bot | TBE")
msg.channel.send(notAllowed)
return;
}
}
if (inputtedCMD === "set") {
if (msg.member.roles.has(adminRole.id) || guildOwner === msg.author.id || msg.author.id === "198590136684904448") {
cmd.run(bot, msg, args, firebaseDB).then(() => {
console.log("[COMMAND] User w/ permission ran '" + inputtedCMD + "'")
return;
});
} else {
const notAllowed = new Discord.RichEmbed()
.setAuthor("Hey, " + msg.author.tag, bot.user.displayAvatarURL)
.setDescription("**__No access__** \n *You need the required role to be able to use that command.*")
.setColor("#00A6ff")
.setTimestamp()
.setFooter("Ticket Bot | TBE")
msg.channel.send(notAllowed)
return;
}
}
if (inputtedCMD === "config","help","invite","patchNotes","ticket") {
if (msg.member.roles.has(adminRole.id) || msg.member.roles.has(generalRole.id) || guildOwner === msg.author.id || msg.author.id === "198590136684904448") {
cmd.run(bot, msg, args, firebaseDB).then(() => {
console.log("[COMMAND] User w/ permission ran '" + inputtedCMD + "'")
return;
})
} else {
const notAllowed = new Discord.RichEmbed()
.setAuthor("Hey, " + msg.author.tag, bot.user.displayAvatarURL)
.setDescription("**__No access__** \n *You need the required role to be able to use that command.*")
.setColor("#00A6ff")
.setTimestamp()
.setFooter("Ticket Bot | TBE")
msg.channel.send(notAllowed)
return;
}
}
我希望只有服务器所有者和机器人创建者能够使用 databaseReset(机器人创建者 ID 是包含的 ID [顺便说一句])
应该只允许服务器的管理员角色和服务器所有者和机器人创建者使用“set”命令。
应该允许具有一般机器人使用角色的每个人使用“config”、“help”、“invite”、“patchNotes”和“ticket”。
【问题讨论】:
标签: node.js visual-studio-code discord.js