Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
119
rated 0 times [  121] [ 2]  / answers: 1 / hits: 28220  / 6 Years ago, tue, april 3, 2018, 12:00:00

My problem is that I want my discordbot wait during the giveaway until the giveway is out



Here's my code :



        const Discord = require('discord.js');
const client = new Discord.Client();
const config = require(./config.json);
var prefix = config.prefix;
client.login(config.token);

client.on('ready',() => {
console.log('I'm online');
})

client.on('message', message => {

const args = message.content.slice(prefix.length).trim().split(/ +/g);
const command = args.shift().toLowerCase();


if (command === 'gstart') {
var channel = args[0].slice(2).slice(0, -1);
var price = args[1];
var End = args[2];
var EndMS = End*1000;
client.channels.get(channel).send({embed: {
color: 3447003,
author: {
name: '',
icon_url: ''
},
title: ,
url: ,
description: ,
fields: [{
name: 'a Giveaway just started !',
value: 'Put'🎉' in react of this message to try to win '' + price + ''.'
},
],
timestamp: '',
footer: {
icon_url: '',
text: 'End in ' + End + ' secondes !'
}
}
})
.then(msg => {
msg.react('🎉');
client.channels.get(channel).send('STUFF')(EndMS); // my problem is here
})
}


He must wait EndMS milis and, after, choose a winner but for now, he send instantly STUFF, for choosing the winner, I will not ask it for you.
All I want is he wait before sending Stuff.



Thanks you for helping me.


More From » wait

 Answers
9

Well it depends. If you trust on the bot's uptime (if the bot wont ever crash or restart during a giveaway) you can use a setTimeout:



setTimeout(function(){ 
doSomething();
}, 3000);


This will run doSomething() after 3 seconds (3000 milliseconds).

So what you need to basically do is:



.then(msg => {
msg.react('🎉');
setTimeout(function(){
client.channels.get(channel).send(It's finished!);
}, EndMS);
})


Note: You might have to tweak the EndMS part.


[#54784] Friday, March 30, 2018, 6 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
dequant

Total Points: 88
Total Questions: 99
Total Answers: 95

Location: Ukraine
Member since Sun, Dec 13, 2020
4 Years ago
dequant questions
;