gpt4 book ai didi

javascript - Discord.js permissionOverwrites 不起作用但完全没有错误

转载 作者:行者123 更新时间:2023-12-05 04:39:43 27 4
gpt4 key购买 nike

我一直在为我们公司开发票务机器人,但最终无法更新每个 channel 的用户权限。

我找不到任何问题,并且代码在权限之外工作得很好。我正在使用 DiscordJS 12.5.1。

这是我的代码:

module.exports = {
name: 'ticket',
category: 'Ticket',
description: 'Creates a new ticket.',
aliases: ['new'],
usage: 'new',
userperms: [],
botperms: [],
run: async (client, message, args, prefix) => {
const discord = require('discord.js');

message.guild.channels
.create(
`ticket-${message.author.username}-${message.author.discriminator}`,
{
permissionOverwrites: [
{
id: message.author.id,
allow: ['CREATE_INSTANT_INVITE'],
allow: ['SEND_MESSAGES'],
allow: ['ATTACH_FILES'],
allow: ['CONNECT'],
allow: ['ADD_REACTIONS'],
allow: ['VIEW_CHANNEL'],
},
],
type: 'text',
// parent: 'category id',
},
)
.then(async (channel) => {
let category = client.channels.cache.find(
(c) => c.name == '➣ Online Tickets' && c.type == 'category',
);
if (!category) throw new Error('Category channel does not exist');
channel.setParent(category.id);

// channel.permissionOverwrites.create(message.author.id, {VIEW_CHANNEL: true, SEND_MESSAGES: false});
// channel.permissionOverwrites.create(message.guild.roles.everyone, {VIEW_CHANNEL: false});

var embedParent = new discord.MessageEmbed()
.setTitle(`Beste, ${message.author.username}`)
.setDescription(
'Een van onze medewerkers helpt je z.s.m! Laat alvast een bericht achter zodat wij je zo goed mogelijk kunnen helpen. Om U zo goed mogelijk te kunnen helpen komen nu enkele vragen, gelieve deze te beantwoorden.\nReageer met 1️⃣ voor een technische vraag \nReageer met 2️⃣ voor boekhouding en juridische vragen.\nReageer met 3️⃣ voor een samenwerking.\nReageer met 4️⃣ voor overige vragen. \n\n ***LET OP: Als U errors krijgt op uw server, kunt U het beste een ticket aanmaken op de website: snip ***',
)
.setColor('007BFF')
.setFooter(
'© OnlineNode.nl 2021 - Ticket Systeem',
'https://media.discordapp.net/attachments/735827815521452133/830082858470604870/logo_400x400.png',
)
.setTimestamp();

channel.send(embedParent).then(function (embedParent) {
embedParent.react('1️⃣');
embedParent.react('2️⃣');
embedParent.react('3️⃣');
embedParent.react('4️⃣');
//embedParent.react("5️⃣")
});
message.guild.channels.cache
.find((c) => c.name == '🗃┃-discord-logs')
.send('New ticket has been submitted!');
});
},
};

最佳答案

您的 permissionOverwrites 数组有一个对象,您可以在其中多次重复 allow 键:

{
permissionOverwrites: [
{
id: message.author.id,
allow: ['CREATE_INSTANT_INVITE'],
allow: ['SEND_MESSAGES'],
allow: ['ATTACH_FILES'],
allow: ['CONNECT'],
allow: ['ADD_REACTIONS'],
allow: ['VIEW_CHANNEL'],
},
],
type: 'text',
}

由于一个对象不能有两个同名的key,基本是这样的:

{
permissionOverwrites: [
{
id: message.author.id,
allow: ['VIEW_CHANNEL'],
},
],
type: 'text',
}

allow是用户或 Angular 色允许的权限数组:

{
permissionOverwrites: [
{
id: message.author.id,
allow: [
'ADD_REACTIONS',
'ATTACH_FILES',
'CONNECT',
'CREATE_INSTANT_INVITE',
'SEND_MESSAGES',
'VIEW_CHANNEL',
],
},
],
type: 'text',
}

另一个错误是,当您使用 setParent 设置 channel 的父级时方法,它会覆盖您刚刚添加的权限并将它们设置为与父 channel 相同。

setParent 方法接受 an options object作为它的第二个参数。它的属性之一是 lockPermissions。它告诉是否将权限锁定为父级的权限,其默认值为 true。为防止同步权限,您可以将其设置为 false,如下所示:

channel.setParent(category.id, { lockPermissions: false });

关于javascript - Discord.js permissionOverwrites 不起作用但完全没有错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70394392/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com