discord.js 发送消息前等待
discord.js wait before send message
我的问题是我想让我的 discordbot 在赠品期间等待,直到赠品用完
这是我的代码:
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
})
}
他必须等待 EndMS milis,然后选择获胜者,但现在,他立即发送 STUFF,选择获胜者,我不会要求你。
我只希望他在发送 Stuff 之前等待。
谢谢你的帮助。
这取决于。如果您相信机器人的正常运行时间(如果机器人在赠品期间不会崩溃或重启),您可以使用 setTimeout:
setTimeout(function(){
doSomething();
}, 3000);
这将在 3 秒(3000 毫秒)后 运行 doSomething()
。
所以你基本上需要做的是:
.then(msg => {
msg.react('');
setTimeout(function(){
client.channels.get(channel).send("It's finished!");
}, EndMS);
})
注意:您可能需要调整 EndMS 部分。
我的问题是我想让我的 discordbot 在赠品期间等待,直到赠品用完
这是我的代码:
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
})
}
他必须等待 EndMS milis,然后选择获胜者,但现在,他立即发送 STUFF,选择获胜者,我不会要求你。 我只希望他在发送 Stuff 之前等待。
谢谢你的帮助。
这取决于。如果您相信机器人的正常运行时间(如果机器人在赠品期间不会崩溃或重启),您可以使用 setTimeout:
setTimeout(function(){
doSomething();
}, 3000);
这将在 3 秒(3000 毫秒)后 运行 doSomething()
。
所以你基本上需要做的是:
.then(msg => {
msg.react('');
setTimeout(function(){
client.channels.get(channel).send("It's finished!");
}, EndMS);
})
注意:您可能需要调整 EndMS 部分。