In the line of “message.channel.awaitmessages” i think the code is bad writted, the thing i want to do is to await for 1 message that is a number btw 0 and 23.
Here is the corresponding code :
JavaScript
x
36
36
1
client2.on("message", (message) => {
2
if(message.bot){return;} //if its a bot - disregard
3
if(message.content[0] !== prefix ){return;} //if its not a command by the user - disregard
4
const args = message.content.slice(prefix.length).trim().split(/ +/g);
5
const command = args.shift().toLowerCase();
6
if (command === 'collect') {
7
const id = message.member.id;
8
const filter = m => m.content.endsWith('h');
9
message.channel.send(scheduler1).then(function(message) {
10
message.react('1️⃣')
11
.then(() => message.react('2️⃣'))
12
.then(() => message.react('3️⃣'))
13
.then(() => message.react('3️⃣'))
14
.then(() =>message.awaitReactions((reaction, user) =>(reaction.emoji.name == '1️⃣' || reaction.emoji.name == '2️⃣' || reaction.emoji.name == '3️⃣' || reaction.emoji.name == '4️⃣'),
15
{ max: 1, time: 30000 }).then(collected => {
16
if (collected.first().emoji.name == '1️⃣') {
17
message.edit(scheduler2);
18
message.clearReactions();
19
console.log("try");
20
message.channel.awaitMessages(filter, {max: 1, time: 6000, errors: ['time']})
21
.then(message.channel.send(collected))
22
.catch(collected => console.log(`After a minute, only ${collected.size} out of 4 voted.`));
23
}
24
if (collected.first().emoji.name == '2️⃣') {
25
message.edit(scheduler3);
26
message.clearReactions();
27
}
28
if (collected.first().emoji.name == '3️⃣') {
29
message.edit(scheduler4);
30
message.clearReactions();
31
}
32
}).catch(() => {
33
message.edit('No answer after 30 seconds, operation canceled.');
34
}));
35
})}
36
Advertisement
Answer
You need to update your filter for this to work:
JavaScript
1
2
1
const filter = m => Number(m.content) >= 1 && Number(m.content) <= 23;
2
Additionally the .then() needs a collected
too.
JavaScript
1
4
1
message.channel.awaitMessages(filter, {max: 1, time: 6000, errors: ['time']})
2
.then(collected => message.channel.send(collected.first().content))
3
.catch(collected => console.log(`After a minute, only ${collected.size} out of 4 voted.`));
4
It would also be worth trying out async / await
. Wich would allow you to do:
JavaScript
1
39
39
1
client2.on('message', async (message) => {
2
if(message.bot) return; // if its a bot - disregard
3
if(message.content[0] !== prefix) return; // if its not a command by the user - disregard
4
const args = message.content.slice(prefix.length).trim().split(/ +/g);
5
const command = args.shift().toLowerCase();
6
if (command === 'collect') {
7
const id = message.member.id;
8
const msg = await message.channel.send(scheduler1);
9
await msg.react('1️⃣');
10
await msg.react('2️⃣');
11
await msg.react('3️⃣');
12
await msg.react('3️⃣');
13
const filter = (reaction, user) => (reaction.emoji.name == '1️⃣' || reaction.emoji.name == '2️⃣' || reaction.emoji.name == '3️⃣' || reaction.emoji.name == '4️⃣');
14
const collected = await msg.awaitReactions(filter, { max: 1, time: 30000 })
15
.catch(() => {
16
msg.edit('No answer after 30 seconds, operation canceled.');
17
return;
18
});
19
if(!collected) return;
20
if (collected.first().emoji.name == '1️⃣') {
21
msg.edit(scheduler2);
22
msg.clearReactions();
23
console.log('try');
24
const filter2 = m => Number(m.content) >= 1 && Number(m.content) <= 23;
25
const collected2 = await msg.channel.awaitMessages(filter2, { max: 1, time: 6000, errors: ['time'] });
26
msg.channel.send(collected2.first().content)
27
.catch(collectedx => console.log(`After a minute, only ${collectedx.size} out of 4 voted.`));
28
}
29
if (collected.first().emoji.name == '2️⃣') {
30
msg.edit(scheduler3);
31
msg.clearReactions();
32
}
33
if (collected.first().emoji.name == '3️⃣') {
34
msg.edit(scheduler4);
35
msg.clearReactions();
36
}
37
}
38
});
39