Error

let cateFive = interaction.guild.channels.cache.find(cat=> cat.name === "meta logs")
let cateFiveID = cateFive.id

interaction.guild.channels.create('🔨meta-logs', {
type: 'GUILD_TEXT',
permissionOverwrites: [{
id: interaction.guild.id,
deny: ['VIEW_CHANNEL'],
}],
parent: cateFiveID
})

let logChannel = interaction.guild.channels.cache.find(channel => channel.name === "🔨meta-logs")
let channel = logChannel.id
let cateFive = interaction.guild.channels.cache.find(cat=> cat.name === "meta logs")
let cateFiveID = cateFive.id

interaction.guild.channels.create('🔨meta-logs', {
type: 'GUILD_TEXT',
permissionOverwrites: [{
id: interaction.guild.id,
deny: ['VIEW_CHANNEL'],
}],
parent: cateFiveID
})

let logChannel = interaction.guild.channels.cache.find(channel => channel.name === "🔨meta-logs")
let channel = logChannel.id
I get a error TypeError: Cannot read properties of undefined (reading 'id')
19 Replies
Frosty
FrostyOP•3y ago
The error comes in this line:
let logChannel = interaction.guild.channels.cache.find(channel => channel.name === "🔨meta-logs")
let logChannel = interaction.guild.channels.cache.find(channel => channel.name === "🔨meta-logs")
megatank58
megatank58•3y ago
await the guild.channels.create and even better, set logchannel to the resolved promise since it returns the channel
Frosty
FrostyOP•3y ago
Also another thing, my bot has admin perms, but doesn't use emojis from other servers. Why is that so? So it created the channel n stuff. But then this comes as invalid:
let logChannel = interaction.guild.channels.cache.find(channel => channel.name === "🔨meta-logs")
let channel = logChannel.id
let logChannel = interaction.guild.channels.cache.find(channel => channel.name === "🔨meta-logs")
let channel = logChannel.id
channel is undefined The bot is in 2 servers, the emoji is in 1 of the servers.
megatank58
megatank58•3y ago
did you resolve the promise?
Frosty
FrostyOP•3y ago
How?
megatank58
megatank58•3y ago
Also the everyone role needs use external emoji permission for the bot to use external emojis if you use interactions
Frosty
FrostyOP•3y ago
Like i get this in the title
megatank58
megatank58•3y ago
I would recommend learning up on promises if you haven't yet
d.js docs
d.js docs•3y ago
Resources to understand Promise: • MDN: learn more • Guide: learn more • JavaScript info: learn more
megatank58
megatank58•3y ago
The general format for emojis is <:name:id> actually
Frosty
FrostyOP•3y ago
I know, in the code it looks like this <:META_SHIELD_MODERATOR:987691307126362113>
megatank58
megatank58•3y ago
then check the permissions thing
Frosty
FrostyOP•3y ago
Bot has admin
megatank58
megatank58•3y ago
for @everyone role
Frosty
FrostyOP•3y ago
That worked.
megatank58
megatank58•3y ago
đź‘Ť Learn up on promises and you would also be able to resolve that promise and move forward
Frosty
FrostyOP•3y ago
But why is this undefined. There is a channel names like that.
megatank58
megatank58•3y ago
Yes but you didn't resolve the promise so the channel has technically not yet been made
Frosty
FrostyOP•3y ago
Is the resolving required?
await interaction.guild.channels.create('🔨meta-logs', {

return new Promise(resolve => {

type: 'GUILD_TEXT',
permissionOverwrites: [{
id: interaction.guild.id,
deny: ['VIEW_CHANNEL'],
}],
parent: cateFiveID

})

})
await interaction.guild.channels.create('🔨meta-logs', {

return new Promise(resolve => {

type: 'GUILD_TEXT',
permissionOverwrites: [{
id: interaction.guild.id,
deny: ['VIEW_CHANNEL'],
}],
parent: cateFiveID

})

})
Like this? What am i missing? Im looking at the djs guide atm, i don't really see anything there about it. But doesn't guild.create already return a promise? Something like this?
const channelCreting = await interaction.guild.channels.create('🔨meta-logs', {
type: 'GUILD_TEXT',
permissionOverwrites: [{
id: interaction.guild.id,
deny: ['VIEW_CHANNEL'],
}],
parent: cateFiveID
}).then(result => {
console.log('Here is channel id', result.id)

})
const channelCreting = await interaction.guild.channels.create('🔨meta-logs', {
type: 'GUILD_TEXT',
permissionOverwrites: [{
id: interaction.guild.id,
deny: ['VIEW_CHANNEL'],
}],
parent: cateFiveID
}).then(result => {
console.log('Here is channel id', result.id)

})
So i remove await ig I don't get what you mean xd Ye, but what do i put inside the console.log, or how do i get the result So the channel id will be channelCreating.id I have this: let channel = channelCreating.id and in embed i have <#${channel}> but it comes as undefined. https://srcb.in/9xAsQYqH0e First one is category https://sourceb.in/nhlglf5GTk Made the changes Oh wait, accident Oh alright it worked. Thank you very much. I'll prolly come back some time coz i might still run into some issues. Yeah, so when i wanna create a role, i also do the promise right?
const roleCreating = await interaction.guild.roles.create({
data: {
name: 'Meta Mod',
color: '767676',
},
reason: 'Meta Setup',
})

let metaRole = roleCreating.id
const roleCreating = await interaction.guild.roles.create({
data: {
name: 'Meta Mod',
color: '767676',
},
reason: 'Meta Setup',
})

let metaRole = roleCreating.id
Just tested it, it retures the roleCreating as undefined. https://sourceb.in/al3MYYbcPJ Oh wait, it was my dum dum in the embed thingy. But it doesn't edit the role, meaning it creates the role but doesn't name it and doesn't give color I think it's something with data: etc.. Really? Just name?
const roleCreating = await interaction.guild.roles.create({

name: 'Meta Mod',
color: '767676',
reason: 'Meta Setup',
})

let metaRole = roleCreating.id
const roleCreating = await interaction.guild.roles.create({

name: 'Meta Mod',
color: '767676',
reason: 'Meta Setup',
})

let metaRole = roleCreating.id
Yeah that worked
Want results from more Discord servers?
Add your server