I am currently making a discord bot using discord.js and i am trying to make a menu mand so when a user types [prefix]menu it sends a picture of the menu i can do that easily but i am trying to make it multipaged, i know i could just make a menu1, menu2 and menu3 mand but id like to have a mand saying nextpage and previouspage this is what i have so far but it doesn't work and there is no errors
if (mand === "menu") {
output()
message.channel.send({file: './images/menu1.png'});
curPage = 1;
}
if (mand === "next page") {
output()
curPage++;
if(curPage >= 3) {
output()
curPage = 3; message.channel.send("You're on the last page!");
}
} else if (mand === "previous page") {
output()
curPage--;
if(curPage <= 0) {
output()
curPage = 1; message.channel.send("You're on the first page!");
}
message.channel.send({file: `./images/menu${curPage}.png`});
}
I am currently making a discord bot using discord.js and i am trying to make a menu mand so when a user types [prefix]menu it sends a picture of the menu i can do that easily but i am trying to make it multipaged, i know i could just make a menu1, menu2 and menu3 mand but id like to have a mand saying nextpage and previouspage this is what i have so far but it doesn't work and there is no errors
if (mand === "menu") {
output()
message.channel.send({file: './images/menu1.png'});
curPage = 1;
}
if (mand === "next page") {
output()
curPage++;
if(curPage >= 3) {
output()
curPage = 3; message.channel.send("You're on the last page!");
}
} else if (mand === "previous page") {
output()
curPage--;
if(curPage <= 0) {
output()
curPage = 1; message.channel.send("You're on the first page!");
}
message.channel.send({file: `./images/menu${curPage}.png`});
}
Share
Improve this question
edited Apr 24, 2018 at 13:55
André
4,4974 gold badges32 silver badges58 bronze badges
asked Oct 25, 2017 at 11:23
James MalkinJames Malkin
1492 gold badges2 silver badges15 bronze badges
2 Answers
Reset to default 5Use a ReactionCollector
instead.
A collect
event would be emitted when a user reacts to the targeted message.
Example:
const collector = message.createReactionCollector((reaction, user) =>
user.id === message.author.id &&
reaction.emoji.name === "◀" ||
reaction.emoji.name === "▶" ||
reaction.emoji.name === "❌"
).once("collect", reaction => {
const chosen = reaction.emoji.name;
if(chosen === "◀"){
// Prev page
}else if(chosen === "▶"){
// Next page
}else{
// Stop navigating pages
}
collector.stop();
});
Docs: Message, ReactionCollector, Reaction, User
I think the best way to achieve this, would be with .awaitMessages?
https://discord.js/#/docs/main/stable/class/TextChannel?scrollTo=awaitMessages
It might be worth trying something along these lines, however I'm not 100% sure about how to await multiple times for paging back and forth... I'd be interested in seeing someone elses solution for this.
For example:
if (mand === "menu") {
message.channel.send({file: './images/menu1.png'});
.then(() => {
message.channel.awaitMessages(response => response.content === 'next', {
max: 1,
time: 30000,
errors: ['time'],
})
.then((collected) => {
message.channel.send({file: './images/menu2.png'});
})
.catch(() => {
// Do something with error
});
});
}