#issue with setChannel() function after creating the channel

98 messages · Page 1 of 1 (latest)

jaunty ibexBOT
#
  • What's your exact discord.js npm list discord.js and node node -v version?
  • Not a discord.js issue? Check out #1081585952654360687.
  • Consider reading #how-to-get-help to improve your question!
  • Explain what exactly your issue is.
  • Post the full error stack trace, not just the top part!
  • Show your code!
  • Issue solved? Press the button!
spark moss
#

you compare a channel object to a s tring

glossy pebble
#

yes

#

what

spark moss
#

that wont ever work

glossy pebble
#

o

spark moss
#

and in your else loop you create a channel but never assign it to your userchannel, yet you're using that

glossy pebble
#

well even if i get rid of the if statement

#

i still have the issue of setchannel

spark moss
#

and you're not resolving the promise either

glossy pebble
#

u

spark moss
glossy pebble
spark moss
#

well still

#

you're comparing a string to an object

glossy pebble
#

uh

#

wdum string

#

what string

spark moss
glossy pebble
#

userchannel

spark moss
#

and your userChannel is a Channel object

glossy pebble
#

so

spark moss
#

thats basic js

glossy pebble
#

how do i use that properly

spark moss
#

you cannot compart a string to an object

glossy pebble
#

so how else am i suppose to do that

spark moss
#

compare to <Channel>.name

glossy pebble
#

whatttt

spark moss
#

and check the docs, and/or refresh your js knowledge

glossy pebble
#

ohhhh

#

my gawd

#

wdum tho

#

i am confusion

spark moss
glossy pebble
#

ok soooo

#

i get channel name from userchannel

#

or channel even

spark moss
#

yes

#

but even then

glossy pebble
#

and than print name

#

why is that different tho

spark moss
#

you are creating a channel but doing nothing with it so you arent going to be moved to it by magic

#

because userChannel is a channel object

#

again

#

this is basic js

glossy pebble
#

ok so

#

if i make it

#

?

spark moss
#

yes

glossy pebble
#

ror: Cannot read properties of undefined (reading 'name')

spark moss
#

then your userCHannel doesnt exist

glossy pebble
# spark moss but

what would i ahve to do to make it do that than lol sorry im trying my hardest

spark moss
#

resolve the promise .create returns to a variable and then use setChannel with that variable

glossy pebble
#

it exists when it is created

spark moss
#

yes but your error tells you its undefined

#

you can try adding optional chaining

lunar kernelBOT
#

mdn Optional chaining (?.)
The optional chaining (?.) operator accesses an object's property or calls a function. If the object accessed or function called using this operator is undefined or null, the expression short circuits and evaluates to undefined instead of throwing an error.

glossy pebble
#

where would i chain?

spark moss
#

userChannel?.name

glossy pebble
#

newState.member.voice.setChannel(userChannel?.name).catch((err) => console.error(err))?

spark moss
#

no

#

the optional chaning goes in your if loop

glossy pebble
#

waaaaa

#

t

#

i make a variable?

spark moss
#

to move the member to the channel you just created, resolve the promise create returns to a variable and then use that in your setChannel

glossy pebble
#

do i resolve with await

spark moss
#

yes

glossy pebble
#

ok

#

and i resolve the setchannel promise

spark moss
#

if you plan on doing something with it yes

glossy pebble
#

ok

#
            newState.guild.channels.create({ name: newState.member.user.displayName, type: ChannelType.GuildVoice, parent: '1137198015468281917'})
            await newState.member.voice.setChannel(thisThing).then(console.log('setting the channel')).catch((err) => console.error(err))```
#

this look right?

#

orrrr

#

it not work and i have tried different way with const thisThing = newState.member.voice.setChannel(userChannel?.name).then(console.log('setting the channel')).catch((err) => console.error(err)) newState.guild.channels.create({ name: newState.member.user.displayName, type: ChannelType.GuildVoice, parent: '1137198015468281917'}) await thisThing

spark moss
#

...

#

resolve the promise .create returns

#

const mychannel = await channels.create....
.... .setChannel(mychannel)

#

you seem to be lacking basic js knowladge, i recommen you check out #resources and #rules 3

glossy pebble
#

i am new but i really am trying to learn

#

im not really learning by book tho

#

im more just learning by figuring out different methods and stuffs

spark moss
#

djs is not for beginners, i recommend checking out #resources

glossy pebble
#

ok i will have a look although i did not start with djs

#

i just havent had experience with js beyond djs

#

is the issue

spark moss
#

the code you showed indicates you have a lack of basic js, more especially promises

#

regardless, my answer does not change, i recommend checking out a js guide like freecodecamp

glossy pebble
#

yes i will check it out thank you

#

it is a shame tho i wont be able to do the thing i wanted yet lol

#

i need to earn it