Reputation: 72
I am trying to make a command that gets every channel and role from a server id that the bot is in, then for each channel/role, it copies everything the server id has and creates it. I am having problems getting the permissions of every role in the channels when creating the channel. When I try to execute this command gives me an error of TypeError [INVALID_TYPE]: Supplied parameter is not a User nor a Role.
if (command === 'clone') {
let guild = args[0]
let findguild = client.guilds.cache.get(guild)
let findguildchannels = findguild.channels.cache.forEach(c => message.guild.channels.create(c.name, { type: `${c.type}`, permissionOverwrites: c.permissionOverwrites.map(v => ({
id: message.guild.roles.cache.forEach(role =>(role.id)),
allow: v.allow,
deny: v.deny
})), userLimit: c.userLimit}))
let findguildroles = findguild.roles.cache.forEach(c => message.guild.roles.create({
data: { name: `${c.name}`, color: '#' + c.color.toString(16), permissions: c.permissions.toArray() }
}))
console.log(findguildchannels)
}
Upvotes: 0
Views: 2667
Reputation: 72
I had just needed to do this
if (command === 'clone') {
let guild = args[0]
let findguild = client.guilds.cache.get(guild)
let findguildroles = findguild.roles.cache.forEach(c => message.guild.roles.create({
data: { name: `${c.name}`, color: '#' + c.color.toString(16), permissions: c.permissions.toArray() }
}))
let findguildchannels = findguild.channels.cache.forEach(c => message.guild.channels.create(c.name, { type: `${c.type}`, permissionOverwrites: c.permissionOverwrites.map(v => {
let target = message.guild.roles.cache.get(v.id);
if (!target) return;
return {
id: message.guild.roles.cache.find(r => r.name === target.name),
allow: v.allow,
deny: v.deny
};
}).filter(v => v), userLimit: c.userLimit}))
console.log(findguildchannels)
}
Upvotes: 1