如何在discord.j中使用同一命令创建和设置角色的权限?

发布于 2025-01-16 02:08:31 字数 1691 浏览 2 评论 0原文

我一直在尝试创建一个命令来创建机器人某些操作所需的角色,并且我已成功编写了用于创建角色的代码,但我无法设置角色权限,因为它总是给出错误 代码如下:

} 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

残龙傲雪 2025-01-23 02:08:31

您可以在执行第一个命令之前等待一段时间,或者以某种方式在 generalsetup 命令中设置权限。喜欢;

guild.roles.create({ name: 'Muted', permissions: [Permissions.FLAGS.MANAGE_MESSAGES, Permissions.FLAGS.KICK_MEMBERS] });

You can use a time wait before executing the first command or in a way, you can set permissions in your generalsetup command. Like;

guild.roles.create({ name: 'Muted', permissions: [Permissions.FLAGS.MANAGE_MESSAGES, Permissions.FLAGS.KICK_MEMBERS] });
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文