javascript - VIEW_CHANNEL 权限有问题
问题描述
似乎无法让它发挥作用。如您在此代码中所见,尝试了多种方式。我尝试了我能或至少知道的。我对此有点陌生,所以这对我来说有点难,我不明白错误想说什么!
我试过了VIEW_CHANNEL
,VIEW_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("⛔");
} 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 "⛔":
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)
解决方案
该代码不起作用,因为您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("⛔");
} 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 "⛔":
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;
})
}
}
希望这可以帮助。
推荐阅读
- jmeter - JMeter - 移动设备请求使用 JSR223 和 groovy 进行仿真 - 没有这样的属性:ExpectedConditions 错误
- math - 从初始值重新计算cropdetect参数
- amazon-s3 - 备份存储中的 S3 和 Google Drive?
- python - 有没有更好的方法来使用pop,这样我们就不必创建字典并弹出项目
- python - Pandas 将两列组合成一个 json keyValue 列
- flutter - Flutter中TextField中标签的默认TextStyle是什么?
- javascript - 如何在不重新加载页面的情况下刷新内容(愿望清单)?
- python-3.x - 如何在类本身中调用 python @staticmethod(TypeError:'staticmethod' object is not callable)?
- python - 如何将文件的每个部分写入单独的目录中?
- android - 使用 Custome UI 播放 Youtube 视频