如何在discord.j中使用同一命令创建和设置角色的权限?
我一直在尝试创建一个命令来创建机器人某些操作所需的角色,并且我已成功编写了用于创建角色的代码,但我无法设置角色权限,因为它总是给出错误 代码如下:
} else if (command == 'genelkurulum') {
client.commands.get('generalsetup').execute(message, args)
client.commands.get('rolepermissions').execute(message, args)
generalsetup创建角色,rolepermissions设置角色的权限。 里面的常规设置:
module.exports = {
name: 'generalsetup',
description: "This is important for bot to understand some of the commands",
async execute(message, args) {
if (message.member.permissions.has("ADMINISTRATOR")) {
message.channel.send('```Setup in process```');
message.guild.roles.create({
name: 'Muted',
reason: 'Before giving custom roles, you need to add the roles to server'
})
message.guild.roles.create({
name: 'Member',
reason: 'Before giving custom roles, you need to add the roles to server'
})
} else {
message.reply('Sorry, you are not an admin...')
}
}
}
以及里面的角色权限:
const { Permissions } = require("discord.js");
module.exports = {
name: 'rolepermissions',
description: "Gives the roles the necessary permissions",
async execute(message, args) {
let Muted = message.guild.roles.cache.find(role => role.name === 'Muted');
Muted.setPermissions([Permissions.FLAGS.VIEW_CHANNEL, Permissions.FLAGS.READ_MESSAGE_HISTORY]);
message.channel.send('Role permissions have been set up')
}
}
我怎样才能做到这一点?
代码一开始并没有被分割,我尝试将它们分开来解决问题,但没有成功 但没有对我造成任何伤害,就这样吧
I have been trying to make a command that creates the roles that are necessary for some actions of the bot and I have successfully made the code for creating the roles but I couldn't set the roles permissions because it always gives an error
Here are the codes:
} else if (command == 'genelkurulum') {
client.commands.get('generalsetup').execute(message, args)
client.commands.get('rolepermissions').execute(message, args)
generalsetup creates the roles and rolepermissions sets the permissions of the roles.
generalsetups inside:
module.exports = {
name: 'generalsetup',
description: "This is important for bot to understand some of the commands",
async execute(message, args) {
if (message.member.permissions.has("ADMINISTRATOR")) {
message.channel.send('```Setup in process```');
message.guild.roles.create({
name: 'Muted',
reason: 'Before giving custom roles, you need to add the roles to server'
})
message.guild.roles.create({
name: 'Member',
reason: 'Before giving custom roles, you need to add the roles to server'
})
} else {
message.reply('Sorry, you are not an admin...')
}
}
}
And rolepermissions inside:
const { Permissions } = require("discord.js");
module.exports = {
name: 'rolepermissions',
description: "Gives the roles the necessary permissions",
async execute(message, args) {
let Muted = message.guild.roles.cache.find(role => role.name === 'Muted');
Muted.setPermissions([Permissions.FLAGS.VIEW_CHANNEL, Permissions.FLAGS.READ_MESSAGE_HISTORY]);
message.channel.send('Role permissions have been set up')
}
}
How can I make this work?
The codes weren't serapeted in the beginning, I tried to separate them to fix the problem but it didn't work
but didn't cause me any harm, so let it be that way
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以在执行第一个命令之前等待一段时间,或者以某种方式在
generalsetup
命令中设置权限。喜欢;You can use a time wait before executing the first command or in a way, you can set permissions in your
generalsetup
command. Like;