TypeError [INVALID_TYPE]:提供的参数既不是用户也不是角色。 | Discord.js
TypeError [INVALID_TYPE]: Supplied parameter is not a User nor a Role. | Discord.js
当我第一次写这些函数时,我没有意识到 .overwritePermissions()
擦除设置的权限。注意到错误后回到我的代码,我尝试更新 joinPrivateChannel()
以使用 .updateOverwrite()
以免删除创建频道的用户的频道权限。
作为参考,第一个函数 createPrivateChannel()
每次都完美运行,而第二个函数给我错误 TypeError [INVALID_TYPE]: Supplied parameter is not a User nor a Role.
。我尝试对用户 ID、成员变量、角色 ID 和角色变量进行硬编码(每种方式都有几种不同的方式),但其中 none 有效。我很乐意 provide/clarify 任何请求的信息,感谢您的时间。
async function createPrivateChannel(serverId, channelName, message) {
const guild = await client.guilds.fetch(serverId);
const everyoneRole = guild.roles.everyone;
const staffRole = guild.roles.Owner;
const channel = await guild.channels.create(channelName, 'lobby')
await channel.setParent(lobby_category);
await channel.overwritePermissions([
{type: 'member', id: message.author.id, allow: [Permissions.FLAGS.VIEW_CHANNEL]},
{type: 'role', id: everyoneRole.id, deny: [Permissions.FLAGS.VIEW_CHANNEL]},
]);
channel.send('+start');
return;
}
async function joinPrivateChannel(serverId, channel, message){
const guild = await client.guilds.fetch(serverId);
await channel.updateOverwrite([
{type: 'member', id: message.author.id, allow: [Permissions.FLAGS.VIEW_CHANNEL]},
]);
};
基于 djs 文档的 updateOverwrite
没有任何数组语法。可能你只是误解了参数。
updateOverwrite
have the following parameters: (userOrRole,options,reason).
你的情况
await channel.updateOverwrite(message.author.id,
{VIEW_CHANNEL: true},
);
当我第一次写这些函数时,我没有意识到 .overwritePermissions()
擦除设置的权限。注意到错误后回到我的代码,我尝试更新 joinPrivateChannel()
以使用 .updateOverwrite()
以免删除创建频道的用户的频道权限。
作为参考,第一个函数 createPrivateChannel()
每次都完美运行,而第二个函数给我错误 TypeError [INVALID_TYPE]: Supplied parameter is not a User nor a Role.
。我尝试对用户 ID、成员变量、角色 ID 和角色变量进行硬编码(每种方式都有几种不同的方式),但其中 none 有效。我很乐意 provide/clarify 任何请求的信息,感谢您的时间。
async function createPrivateChannel(serverId, channelName, message) {
const guild = await client.guilds.fetch(serverId);
const everyoneRole = guild.roles.everyone;
const staffRole = guild.roles.Owner;
const channel = await guild.channels.create(channelName, 'lobby')
await channel.setParent(lobby_category);
await channel.overwritePermissions([
{type: 'member', id: message.author.id, allow: [Permissions.FLAGS.VIEW_CHANNEL]},
{type: 'role', id: everyoneRole.id, deny: [Permissions.FLAGS.VIEW_CHANNEL]},
]);
channel.send('+start');
return;
}
async function joinPrivateChannel(serverId, channel, message){
const guild = await client.guilds.fetch(serverId);
await channel.updateOverwrite([
{type: 'member', id: message.author.id, allow: [Permissions.FLAGS.VIEW_CHANNEL]},
]);
};
基于 djs 文档的 updateOverwrite
没有任何数组语法。可能你只是误解了参数。
updateOverwrite
have the following parameters: (userOrRole,options,reason).
你的情况
await channel.updateOverwrite(message.author.id,
{VIEW_CHANNEL: true},
);