- What's your exact discord.js
npm list discord.jsand nodenode -vversion? - 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!
#issue with setChannel() function after creating the channel
98 messages · Page 1 of 1 (latest)
that wont ever work
o
and in your else loop you create a channel but never assign it to your userchannel, yet you're using that
and you're not resolving the promise either
u
wait what
in the if (oldstate.channel.name == userChannel)
channel.name returns a string
userchannel
and your userChannel is a Channel object
so
thats basic js
how do i use that properly
you cannot compart a string to an object
so how else am i suppose to do that
compare to <Channel>.name
whatttt
and check the docs, and/or refresh your js knowledge
channel.name is a string, userChannel is not
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
yes
but
ror: Cannot read properties of undefined (reading 'name')
then your userCHannel doesnt exist
what would i ahve to do to make it do that than lol sorry im trying my hardest
resolve the promise .create returns to a variable and then use setChannel with that variable
the userchannel gets created within the same if statement if that makes a difference
it exists when it is created
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.
where would i chain?
userChannel?.name
newState.member.voice.setChannel(userChannel?.name).catch((err) => console.error(err))?
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
do i resolve with await
yes
if you plan on doing something with it yes
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
...
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
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
djs is not for beginners, i recommend checking out #resources
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