+ 3
[js] setTimeout and return
how can I do function a(){ return 'abc'; } return setTimeout(a(),1000); ? it occurs me an error...
27 Antworten
+ 2
yes
+ 2
not using jquery
+ 2
it occurs me an error
+ 2
setimeout(a,1000); ?
+ 2
it works for my code when in setTimeout I write msg.channel.send() but when it's return, there is not an error but nothing appears
+ 2
let n = msg.content.split('dice ')[1];
if(n<1 || n>6 || n != Math.round(n)) {
return 'The number need to be an integer between 1 and 6';
}
if(!(/\d+/.test(n))) {
return 'Need to be a number !';
}
let r = Math.round(Math.random()*5+1);
let res = (r==n)?'You win':'You lose';
function a() {
return'Your number: '+n+'\nDice result : '+r+'\n'+res;
}
return setTimeout(a,1000);
}
+ 2
if you replace the return on the setTimeout by msg.channel.send() its good
+ 2
but I want return
+ 2
I will try
+ 2
function a() {
return'Your number: '+n+'\nDice result : '+r+'\n'+res;
}setTimeout(a,5000);
return a();
it return immediatly
+ 2
nope......... 😭😭😭 sorry I think I will forgot this idea
+ 2
oh it work but... it print 2 time, one immediatly and a second time 5 sec after
+ 2
so ... window.onload...
+ 1
why are you using setTimeout in return?
+ 1
I'm programming discord bot in js.
so when I write
return a;
my bot write a.
when I write
msg.channel.send(b);
return a;
my bot write
b
a
so I want a cooldown btw b and a
+ 1
You want to delay the return?
+ 1
then use it below the function. Then call it.
+ 1
remove a() from the timeout just put a
+ 1
yap
+ 1
https://code.sololearn.com/W5aTHsNlc5lh/?ref=app
Just an example.