I'm performing a bot that can help me to create many channels with specific permissions for a tournament. Channels name are "Team1-vs-Team2". In the server we have Roles defined with the same name as each team (i.e. members from "BarcelonaFC" has a role named "BarcelonaFC")
So, let's say that for this round BarcelonaFC faces RealMadrid, then the command executed will be:
$stage
BarcelonaFC-vs-RealMadrid
Then, the result should be the creation of a channel named "BarcelonaFC-vs-RealMadrid" with roles BarcelonaFC and RealMadrid assigned to it with specific permissions
This is my code (it's adjusted only to assign BarcelonaFC role with the HOME info) :
client.on('message', (message) => {
if (message.author.bot) return;
if (message.content.startsWith(process.env.PREFIX)) {
const [CMD_NAME, ...args] = message.content
.trim()
.substring(process.env.PREFIX.length)
.split(/\n+/);
if (CMD_NAME === 'del') {
message.guild.channels.cache.forEach(channel => channel.delete());
message.guild.channels.create('General', { type: 'text' });
message.guild.channels.create('FRENTE XXXX', { type: 'category' });
}
if (CMD_NAME === 'stage') {
if (args.length == 0) return message.reply('Please provide a stage number and teams');
var i;
for (i = 0; i < process.env.QTY_LLAVES; i++) {
const [HOME, AWAY] = args[i].split('-vs-');
let roleH = message.guild.roles.cache.find(r => r.name === HOME);
message.guild.channels.create(args[i], {
type: 'text',
permissionOverwrites: [
{
id: roleH.id,
allow: permAllowed,
deny: permDenied,
},
],
}).then((channel) => {
const categoryId = message.guild.channels.cache.find(cat => cat.name === 'FRENTE XXXX');
channel.setParent(categoryId);
})
As a result, I have an error on following line within permissionsOverwrites:
id: roleH.id,
Error obtained
C:\Users\alexi\Desktop\Discord\OESTE-FWT\pikabot\src\pikabot.js:121
id: roleH.id,
^
TypeError: Cannot read property 'id' of undefined
at Client.<anonymous> (C:\Users\alexi\Desktop\Discord\OESTE-FWT\pikabot\src\pikabot.js:121:39)
I need help please to identify why is 'undefined' and why I got this error. Thanks in advance
EDIT: After roleH assignment, I've run a console.log(roleH) and get this for the first iteration: IMPORTANT NOTE: The role I've used here is called 'boca' (it's an latin team). Sorry to not used Barcelona or Real Madrid.
Role {
guild: <ref *1> Guild {
members: GuildMemberManager {
cacheType: [class Collection extends Collection],
cache: [Collection [Map]],
guild: [Circular *1]
},
channels: GuildChannelManager {
cacheType: [class Collection extends Collection],
cache: [Collection [Map]],
guild: [Circular *1]
},
roles: RoleManager {
cacheType: [class Collection extends Collection],
cache: [Collection [Map]],
guild: [Circular *1]
},
presences: PresenceManager {
cacheType: [class Collection extends Collection],
cache: Collection(0) [Map] {}
},
voiceStates: VoiceStateManager {
cacheType: [class Collection extends Collection],
cache: Collection(0) [Map] {},
guild: [Circular *1]
},
deleted: false,
available: true,
id: '836369921939210250',
shardID: 0,
name: "pilo's server",
icon: null,
splash: null,
discoverySplash: null,
region: 'brazil',
memberCount: 3,
large: false,
features: [],
applicationID: null,
afkTimeout: 300,
afkChannelID: null,
systemChannelID: null,
embedEnabled: undefined,
premiumTier: 0,
premiumSubscriptionCount: 0,
verificationLevel: 'NONE',
explicitContentFilter: 'DISABLED',
mfaLevel: 0,
joinedTimestamp: 1619656895701,
defaultMessageNotifications: 'ALL',
systemChannelFlags: SystemChannelFlags { bitfield: 0 },
maximumMembers: 100000,
maximumPresences: null,
approximateMemberCount: null,
approximatePresenceCount: null,
vanityURLCode: null,
vanityURLUses: null,
description: null,
banner: null,
rulesChannelID: null,
publicUpdatesChannelID: null,
preferredLocale: 'en-US',
ownerID: '440862122201579520',
emojis: GuildEmojiManager {
cacheType: [class Collection extends Collection],
cache: Collection(0) [Map] {},
guild: [Circular *1]
}
},
id: '840675247035383890',
name: 'boca',
color: 2123412,
hoist: false,
rawPosition: 5,
permissions: Permissions { bitfield: 1983368913 },
managed: false,
mentionable: false,
deleted: false
}