好了,我一直在开发一个机器人,它可以使用discord.js创建通道覆盖。我对discord.js比较陌生,但是我看了这个纪录片,似乎在更改覆盖时使用的正确方法是我在下面的代码中使用的方法,但我得到了一个错误消息,并且我完全不知道如何修复它。
if (command == 'lockdown') {
if (commandArgs == '') {
let channel = msg.channel;
let roles = msg.guild.roles;
console.log(roles);
let testRole = 708384707015868486;
channel
.overwritePermissions(testRole, { SEND_MESSAGES: false }, 'closing up shop')
.then(console.log)
.catch(console.log);
}
}这是该特定命令的代码,但我得到以下错误消息。
TypeError [INVALID_TYPE]: Supplied overwrites is not an Array or Collection of Permission Overwrites.
at TextChannel.overwritePermissions (/home/runner/Ecliptical-Productions-V3/node_modules/discord.js/src/structures/GuildChannel.js:208:9)
at Client.<anonymous> (/home/runner/Ecliptical-Productions-V3/index.js:25:17)
at Client.emit (events.js:315:20)
at Client.EventEmitter.emit (domain.js:483:12)
at MessageCreateAction.handle (/home/runner/Ecliptical-Productions-V3/node_modules/discord.js/src/client/actions/MessageCreate.js:31:14)
at Object.module.exports [as MESSAGE_CREATE] (/home/runner/Ecliptical-Productions-V3/node_modules/discord.js/src/client/websocket/handlers/MESSAGE_CREATE.js:4:32)
at WebSocketManager.handlePacket (/home/runner/Ecliptical-Productions-V3/node_modules/discord.js/src/client/websocket/WebSocketManager.js:384:31)
at WebSocketShard.onPacket (/home/runner/Ecliptical-Productions-V3/node_modules/discord.js/src/client/websocket/WebSocketShard.js:444:22)
at WebSocketShard.onMessage (/home/runner/Ecliptical-Productions-V3/node_modules/discord.js/src/client/websocket/WebSocketShard.js:301:10)
at WebSocket.onMessage (/home/runner/Ecliptical-Productions-V3/node_modules/ws/lib/event-target.js:125:16) {
[Symbol(code)]: 'INVALID_TYPE'
}如何修复此错误?我在命令后检查了通道覆盖,但没有进行更改,我已经尝试了很长时间来解决这个问题,但我找不到这个错误。
发布于 2020-09-15 14:34:38
overwritePermissions方法需要一个数组或一个OverwriteResolvables集合作为第一个参数。相反,您的第一个参数是要更改其权限的角色的id。
将channel.overwritePermissions更改为下面的示例代码,并尝试一下。
channel.overwritePermissions(
[
{
id: testRole,
deny: ['SEND_MESSAGES'],
},
],
'Closing up shop'
);在本例中,提供的OverwriteResolvable的类型为OverwriteData,可以使用简单的对象结构进行定义。
发布于 2020-09-15 14:41:14
overwritePermissions需要一个数组,而你给它提供了两个对象。
channel.overwritePermissions(
[ //<--- you are missing these
{
id: message.author.id,
deny: ['SEND_MESSAGES'],
},
], //<--- you are missing these
'Needed to change permissions'
);https://discord.js.org/#/docs/main/stable/class/GuildChannel?scrollTo=overwritePermissions
发布于 2020-10-30 03:53:30
如果你已经定义了" message“,你可以使用"message.channel”来获取你输入消息的通道。
message.channel.createOverwrite(message.guild.id, { SEND_MESSAGES: false })
你可以在上面看到,这将改变所有角色的发送消息权限,除了主持人角色,如果你想发送消息后,你可以使用".then()“函数,如果你使用V12我告诉你的一切都会很好,我建议你在询问之前先研究一下,你可以在网上找到大量的信息和教程。
https://stackoverflow.com/questions/63895612
复制相似问题