【问题标题】:permission over write after channel creation, using discord.js使用 discord.js 创建频道后的写入权限
【发布时间】:2022-01-18 23:11:36
【问题描述】:

我在授予message.author 和员工权限以在创建频道后立即查看频道时遇到一些问题,问题是,当频道的父级(类别)更改时,它会同步父级(类别)的权限),不允许用户和工作人员看到频道,我不知道如何解决这个问题,我希望我解释清楚,如果您有任何问题,请询问。

这是我的代码:

module.exports = {
  name: 'new',
  category: 'Ticket',
  description: 'Creates a new ticket.',
  aliases: ['newticket'],
  usage: 'New',
  userperms: [],
  botperms: [],
  run: async (client, message, args) => {
    if(message.author.bot) return;
    if(!message.channel.id == process.env.COMMAND_T) return;
if(!client.userTickets) {
  client.userTickets = new Map();

  const channels = message.guild.channels.cache.filter(channel => {
    if(channel) return channel.name.startsWith('t-');
    });

    if(channels) {
      for (i in Array.from(channels)) {
        client.userTickets.set(i, +i + 1);
    }
  }
}
console.log(client.userTickets)
        if(client.userTickets.has(message.author.id)) {
            return message.channel.send('<@' + message.author.id + 'You already have a ticket, please close it then run this command again!').then(m => m.delete({timeout: 10000}));
        }
        message.guild.channels.create(`t-${client.userTickets.size + 1}`, {
            permissionOverwrites: [
                {
                    id: message.author.id,
                    allow: ['SEND_MESSAGES', 'VIEW_CHANNEL'],
                },
                {
                    id: process.env.ROLE_STAFF,
                    allow: ['SEND_MESSAGES', 'VIEW_CHANNEL'],
                },
                {
                    id: process.env.ROLE_MEMBER,
                    deny: ['VIEW_CHANNEL']
                }
            ],
            type: 'text',
        }).then(async channel => {
            channel.setParent(process.env.TICKET_C);
            client.userTickets.set(message.author.id, client.userTickets.size + 1);
            message.channel.send(`<@` + message.author.id + `>, Done, go to your ticket! ${channel}`).then(m => m.delete({timeout: 10000}));
            client.users.cache.get(message.author.id).send(`Your ticket has been opened, go take a look: ${channel}`)
            channel.send(`Hi <@` + message.author.id + `>, Hello and welcome to your DwaCraft ticket!`);
            channel.send(`https://tenor.com/view/is-there-something-i-can-help-you-with-dan-levy-david-david-rose-schitts-creek-gif-20776045`);
            
            const logchannel = message.guild.channels.cache.find(channel => channel.id === process.env.TICKET_L);
            
            if(logchannel) {
                logchannel.send(`There was a new ticket created by <@${message.author.id}>! Channel: <#${channel.id}>`);
            }
        });
    }
}

注意:我已经研究过,但没有找到任何答案。

感谢您抽出宝贵时间阅读本文。

【问题讨论】:

    标签: javascript discord.js


    【解决方案1】:

    试试这个

    message.guild.channels.create(`t-${client.userTickets.size + 1}`, {
                    type: 'GUILD_TEXT',
                    permissionOverwrites: [
                        {
                            id: process.env.ROLE_STAFF,
                            allow: ['VIEW_CHANNEL'],
                        },
                        {
                            id: message.author.id,
                            allow: ['VIEW_CHANNEL'],
                        },
                    ],
                    parent: process.env.CATEGORY
                });
    

    这段代码是我的,但它被缩短了,如果你喜欢完整的给我发DM

    P.S 我只是为我的票务系统准备了它

    【讨论】:

    • 我忘了编辑问题,我找到了解决问题的方法,首先设置父级然后更改权限,我现在有一个新问题,我数据库新手,但我想制作门票数据库。 (不过,我会为此提出另一个问题。)
    • 好吧,我希望我能帮助你,你可以找到我的方法:! Richi OV#1700 或在我的社区discord.com/invite/xEUDMGTeRt
    猜你喜欢
    • 2018-03-04
    • 2021-08-05
    • 2021-02-01
    • 2023-03-27
    • 2021-09-19
    • 2021-10-12
    • 2020-07-26
    • 2021-04-10
    • 2020-08-12
    相关资源
    最近更新 更多