#undefined return from collector
1 messages · Page 1 of 1 (latest)
what is temp?
you .then() a promise, you await that promise but don't assign it to a variable
so where do youe expect that value to come from?
So it logs yes (line 72) then it logs test for line 75 and then it logs undefined for the console.log of temp
@livid snow here, to not have t ping-pong with other conversations
what's line 72?
You are the best im sorry, heres a screenshot with the full code
you don't log anything on 72 
basically i want to assign the outcome of confirmannouncement to a variable
so i return something in the function and it doesnt assign
Uhh sorry 2 lines down, cus i added the console log for temp
again, where do you try to log the response? your code does not align with what you're trying to do, really
So it logs yes (line 74) then it logs test for line 77 and then it logs undefined for the console.log of temp
can you show another screenshot of what you actually have? else this is prone to misunderstandings
ill remove code that isnt important, this is the essential part
theres some stuff inbetween but the essence is this
i have a variable i want to assign the return of a function to
but it always turns up undefined
nah
yeah, but you don't do that
well, it'd be more like
const foo = await bar().then(v => return "true")
ahh
don't define temp in the outer scope and assign it within the then
just return it from the then, collect it into a variable and return that from the outer scope
okay gonna try thanks for your wisdom!
async function confirm*() {
await interaction.edt();
return interaction.channel.await*().then(v => {
return "some value";
})
}
that's your situation
instead of ```js
async function confirm*() {
let foo = "";
await interaction.edt();
await interaction.channel.await*().then(v => {
foo = "some value"
return foo;
})
}
here you can see why it's undefined
you return foo from the then, but don't do anything with it
you could add a return foo
```js
async function confirm*() {
let foo = "";
await interaction.edt();
await interaction.channel.await*().then(v => {
foo = "some value"
return foo; // this does'nt do anything if you don't use the value the promise resolves with
})
return foo; // here we return from the confirm* fct
}
but you really shouldn't, and instead just properly handle your promises
and cleanly propagate it through the scopes instead of trying to assign it over promises
(might work for this but is terribly error prone)
depends on your use case really,
async/await and then are different ways to deal with promises, for sure
i thought return x easy ill just do that gg but nop xd