首页 > 解决方案 > VIEW_CHANNEL 权限有问题

问题描述

似乎无法让它发挥作用。如您在此代码中所见,尝试了多种方式。我尝试了我能或至少知道的。我对此有点陌生,所以这对我来说有点难,我不明白错误想说什么!

我试过了VIEW_CHANNELVIEW_CHANNELS但它们似乎都不起作用

const Discord = require("discord.js")
const ms = require('ms');

module.exports = {
    name: 'ticket',
    usage: '%ticket <reason>',
    description: 'makes a ticket',

    async execute(client, message, args, cmd, discord) {
        const channel = await message.guild.channels.create(`ticket: ${message.author}`);
        channel.setParent('855596395783127081');

        channel.overwritePermissions([{
            id: channel.guild.roles.everyone,
            deny: ['VIEW_CHANNELS'],
        }, ]);

        channel.overwritePermissions([{
            id: message.author.id,
            allow: ['VIEW_CHANNELS'],
        }]);

        channel.overwritePermissions([{
                id: channel.guild.roles.everyone,
                deny: ['SEND_MESSAGES'],
            },
            {
                id: message.author.id,
                allow: ['SEND_MESSAGES'],
            },
        ]);

        'SEND_MESSAGES'

        const reactionMessage = await channel.send(`Thank you for contacting support! A staff member will be with you as soon as possible`);

        try {

            await reactionMessage.react("");
            await reactionMessage.react("⛔&quot;);
        } catch (err) {
            channel.send(`Error Sending Emojis`);
            throw err;
        }

        const collector = reactionMessage.createReactionCollector((reaction, user) =>
            message.guild.member.cache.find((member) => member.id === userid).hasPermission('ADMINISTRATOR'), { dispose: true }
        );

        collector.on('collect', (reaction, user) => {
            switch (reaction.emoji.name) {
                case "":
                    channel.overwritePermissions([{
                        id: message.author.id,
                        deny: ['SEND_MESSAGES']
                    }, ]);
                    break;
                case "⛔&quot;:
                    message.channel.send('Deleteing ticket in 5 seconds');
                    setTimeout(() => channel.delete(), 5000);
                    break;
            }
        });

        message.channel.send(`We will be right with you! ${channel}`).then((msg) => {
            setTimeout(() => msg.delete(), 7000);
            setTimeout(() => message.delete(), 3000);
        }).catch((err) => {
            throw err;
        })
    }
}

这是错误

PS C:\Users\lolzy\OneDrive\Desktop\discordbot> node .
Cbs slave is online!
(node:18012) UnhandledPromiseRejectionWarning: RangeError [BITFIELD_INVALID]: Invalid bitfield flag or number.
    at Function.resolve (C:\Users\lolzy\OneDrive\Desktop\discordbot\node_modules\discord.js\src\util\BitField.js:150:19)       
    at C:\Users\lolzy\OneDrive\Desktop\discordbot\node_modules\discord.js\src\util\BitField.js:148:54
    at Array.map (<anonymous>)
    at Function.resolve (C:\Users\lolzy\OneDrive\Desktop\discordbot\node_modules\discord.js\src\util\BitField.js:148:40)       
    at Function.resolve (C:\Users\lolzy\OneDrive\Desktop\discordbot\node_modules\discord.js\src\structures\PermissionOverwrites.js:184:25)
    at C:\Users\lolzy\OneDrive\Desktop\discordbot\node_modules\discord.js\src\structures\GuildChannel.js:341:87
    at Array.map (<anonymous>)
    at TextChannel.edit (C:\Users\lolzy\OneDrive\Desktop\discordbot\node_modules\discord.js\src\structures\GuildChannel.js:341:57)
    at TextChannel.overwritePermissions (C:\Users\lolzy\OneDrive\Desktop\discordbot\node_modules\discord.js\src\structures\GuildChannel.js:212:17)
    at Object.execute (C:\Users\lolzy\OneDrive\Desktop\discordbot\commands\ticket.js:13:17)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:18012) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of 
an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 3)
(node:18012) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that 
are not handled will terminate the Node.js process with a non-zero exit code.
(node:18012) UnhandledPromiseRejectionWarning: RangeError [BITFIELD_INVALID]: Invalid bitfield flag or number.
    at Function.resolve (C:\Users\lolzy\OneDrive\Desktop\discordbot\node_modules\discord.js\src\util\BitField.js:150:19)       
    at C:\Users\lolzy\OneDrive\Desktop\discordbot\node_modules\discord.js\src\util\BitField.js:148:54
    at Array.map (<anonymous>)
    at Function.resolve (C:\Users\lolzy\OneDrive\Desktop\discordbot\node_modules\discord.js\src\util\BitField.js:148:40)       
    at Function.resolve (C:\Users\lolzy\OneDrive\Desktop\discordbot\node_modules\discord.js\src\structures\PermissionOverwrites.js:183:26)
    at C:\Users\lolzy\OneDrive\Desktop\discordbot\node_modules\discord.js\src\structures\GuildChannel.js:341:87
    at Array.map (<anonymous>)
    at TextChannel.edit (C:\Users\lolzy\OneDrive\Desktop\discordbot\node_modules\discord.js\src\structures\GuildChannel.js:341:57)
    at TextChannel.overwritePermissions (C:\Users\lolzy\OneDrive\Desktop\discordbot\node_modules\discord.js\src\structures\GuildChannel.js:212:17)
    at Object.execute (C:\Users\lolzy\OneDrive\Desktop\discordbot\commands\ticket.js:18:17)
(node:18012) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of 
an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 4)

标签: javascriptnode.jsdiscord.js

解决方案


该代码不起作用,因为您channel.overwritePermissions多次使用(我对此也有点陌生,所以我没有完整的解释,我只知道它不起作用:P)

而且你还使用VIEW_CHANNELS了代替VIEW_CHANNEL

这段代码对我有用:

const Discord = require("discord.js")
const ms = require('ms');

module.exports = {
    name: 'ticket',
    usage: '%ticket <reason>',
    description: 'makes a ticket',

    async execute(client, message, args, cmd, discord) {
        const channel = await message.guild.channels.create(`ticket: ${message.author}`);
        channel.setParent('855596395783127081');

        channel.overwritePermissions([
            {
                id: channel.guild.roles.everyone,
                deny: ['VIEW_CHANNEL', 'SEND_MESSAGES'],
            },
            {
                id: message.author.id,
                allow: ['VIEW_CHANNEL', 'SEND_MESSAGES'],
            }
            ]);


        const reactionMessage = await channel.send(`Thank you for contacting support! A staff member will be with you as soon as possible`);

        try {

            await reactionMessage.react("");
            await reactionMessage.react("⛔&quot;);
        } catch (err) {
            channel.send(`Error Sending Emojis`);
            throw err;
        }

        const collector = reactionMessage.createReactionCollector((reaction, user) =>
            message.guild.member.cache.find((member) => member.id === userid).hasPermission('ADMINISTRATOR'), { dispose: true }
        );

        collector.on('collect', (reaction, user) => {
            switch (reaction.emoji.name) {
                case "":
                    channel.overwritePermissions([{
                        id: message.author.id,
                        deny: ['SEND_MESSAGES']
                    }, ]);
                    break;
                case "⛔&quot;:
                    message.channel.send('Deleteing ticket in 5 seconds');
                    setTimeout(() => channel.delete(), 5000);
                    break;
            }
        });

        message.channel.send(`We will be right with you! ${channel}`).then((msg) => {
            setTimeout(() => msg.delete(), 7000);
            setTimeout(() => message.delete(), 3000);
        }).catch((err) => {
            throw err;
        })
    }
}

希望这可以帮助。


推荐阅读