why this is not working?

const Discord = require('discord.js');
const client = new Discord.Client({
intents: [
Discord.GatewayIntentBits.Guilds,
Discord.GatewayIntentBits.GuildVoiceStates,
Discord.GatewayIntentBits.MessageContent,
Discord.GatewayIntentBits.GuildMessages,
Discord.GatewayIntentBits.GuildMessageReactions,
Discord.GatewayIntentBits.DirectMessageReactions,
Discord.GatewayIntentBits.GuildEmojisAndStickers,
]
});

client.once('ready', async () => {
console.log('bot is ready!');
});

const prefix = '!';

const pages = [
{
title: 'general commands [1/3]',
description: '!kick - kick user\n!ban - ban user',
emojiLeft: '<:prev:1138580435362906245>',
emojiRight: '<:next:1138580432963780708>',
page: 0
},
{
title: 'song commands [2/3]',
description: '!play - play song\n!skip - skip song',
emojiLeft: '<:prev:1138580435362906245>',
emojiRight: '<:next:1138580432963780708>',
page: 1
},
{
title: 'idk man commands [3/3]',
description: '!command 1 - a command \n!command 2 - a second command',
emojiLeft: '<:prev:1138580435362906245>',
emojiRight: '<:next:1138580432963780708>',
page: 2
}
];

client.on('messageCreate', async message => {
if (message.author.bot) return;
if (!message.content.startsWith(prefix)) return;

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

if (command === 'help' || command === 'commands') {
let page = 0;

const embed = new Discord.EmbedBuilder()
.setTitle(pages[page].title)
.setDescription(pages[page].description)
.setFooter({ text: `Page ${page + 1}/${pages.length}` })
.setColor(0x0099FF);

const msg = await message.channel.send({ embeds: [embed] });

await msg.react(pages[page].emojiLeft);
await msg.react(pages[page].emojiRight);

const filter = (reaction, user) => {
return [pages[page].emojiLeft, pages[page].emojiRight].includes(reaction.emoji.name) && user.id === message.author.id;
};

const collector = msg.createReactionCollector({ filter, time: 60000 });

collector.on('collect', async (reaction, user) => {
if (user.id === message.author.id) {
reaction.users.remove(user);

if (reaction.emoji.name === pages[page].emojiLeft) {
page = (page - 1 + pages.length) % pages.length;
} else if (reaction.emoji.name === pages[page].emojiRight) {
page = (page + 1) % pages.length;
}

embed.setTitle(pages[page].title)
.setDescription(pages[page].description)
.setFooter({ text: `Page ${page + 1}/${pages.length}` });

const editMsg = await msg.edit({ embeds: [embed] });
await editMsg.reactions.removeAll().catch(error => console.error('Failed to remove reactions: ', error));
await editMsg.react(pages[page].emojiLeft);
await editMsg.react(pages[page].emojiRight);
}
});

collector.on('end', async () => {
await msg.reactions.removeAll().catch(error => console.error('Failed to remove reactions: ', error));
});
}
});

client.login('yeah');
const Discord = require('discord.js');
const client = new Discord.Client({
intents: [
Discord.GatewayIntentBits.Guilds,
Discord.GatewayIntentBits.GuildVoiceStates,
Discord.GatewayIntentBits.MessageContent,
Discord.GatewayIntentBits.GuildMessages,
Discord.GatewayIntentBits.GuildMessageReactions,
Discord.GatewayIntentBits.DirectMessageReactions,
Discord.GatewayIntentBits.GuildEmojisAndStickers,
]
});

client.once('ready', async () => {
console.log('bot is ready!');
});

const prefix = '!';

const pages = [
{
title: 'general commands [1/3]',
description: '!kick - kick user\n!ban - ban user',
emojiLeft: '<:prev:1138580435362906245>',
emojiRight: '<:next:1138580432963780708>',
page: 0
},
{
title: 'song commands [2/3]',
description: '!play - play song\n!skip - skip song',
emojiLeft: '<:prev:1138580435362906245>',
emojiRight: '<:next:1138580432963780708>',
page: 1
},
{
title: 'idk man commands [3/3]',
description: '!command 1 - a command \n!command 2 - a second command',
emojiLeft: '<:prev:1138580435362906245>',
emojiRight: '<:next:1138580432963780708>',
page: 2
}
];

client.on('messageCreate', async message => {
if (message.author.bot) return;
if (!message.content.startsWith(prefix)) return;

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

if (command === 'help' || command === 'commands') {
let page = 0;

const embed = new Discord.EmbedBuilder()
.setTitle(pages[page].title)
.setDescription(pages[page].description)
.setFooter({ text: `Page ${page + 1}/${pages.length}` })
.setColor(0x0099FF);

const msg = await message.channel.send({ embeds: [embed] });

await msg.react(pages[page].emojiLeft);
await msg.react(pages[page].emojiRight);

const filter = (reaction, user) => {
return [pages[page].emojiLeft, pages[page].emojiRight].includes(reaction.emoji.name) && user.id === message.author.id;
};

const collector = msg.createReactionCollector({ filter, time: 60000 });

collector.on('collect', async (reaction, user) => {
if (user.id === message.author.id) {
reaction.users.remove(user);

if (reaction.emoji.name === pages[page].emojiLeft) {
page = (page - 1 + pages.length) % pages.length;
} else if (reaction.emoji.name === pages[page].emojiRight) {
page = (page + 1) % pages.length;
}

embed.setTitle(pages[page].title)
.setDescription(pages[page].description)
.setFooter({ text: `Page ${page + 1}/${pages.length}` });

const editMsg = await msg.edit({ embeds: [embed] });
await editMsg.reactions.removeAll().catch(error => console.error('Failed to remove reactions: ', error));
await editMsg.react(pages[page].emojiLeft);
await editMsg.react(pages[page].emojiRight);
}
});

collector.on('end', async () => {
await msg.reactions.removeAll().catch(error => console.error('Failed to remove reactions: ', error));
});
}
});

client.login('yeah');
- bot is not removing emojis when you want to change page - bot is not changing pages
1 Reply
d.js toolkit
d.js toolkit10mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button!