discord.js-pagination icon indicating copy to clipboard operation
discord.js-pagination copied to clipboard

Cannot send empty message

Open DudeThatsErin opened this issue 3 years ago • 5 comments

Screenshot_1

Character Options: https://sourceb.in/KvEEMozyus Help: https://sourceb.in/KLZN2WKfdC

It is not working with Node v14.17.2. I've upgraded DJS to v13 so I need node v14. It worked with Node v12 but now I upgraded and it broke. :(

The embeds all work when sent separately but not when sent with this system.

I have updated the index.js to work with DJS V13 already.

DudeThatsErin avatar Jul 16 '21 18:07 DudeThatsErin

FIXED if anyone else has the issue... copy and paste this to the index.js created by discord.js-pagination... 100% works.

const paginationEmbed = async (msg, pages, emojiList = ['⏪', '⏩'], timeout = 120000) => {
	if (!msg && !msg.channel) throw new Error('Channel is inaccessible.');
	if (!pages) throw new Error('Pages are not given.');
	if (emojiList.length !== 2) throw new Error('Need two emojis.');
	let page = 0;
	const curPage = await msg.channel.send({ embeds: [pages[page].setFooter(`Page ${page + 1} / ${pages.length}`)] });
	for (const emoji of emojiList) await curPage.react(emoji);
	const reactionCollector = curPage.createReactionCollector(
		(reaction, user) => emojiList.includes(reaction.emoji.name) && !user.bot,
		{ time: timeout }
	);
	reactionCollector.on('collect', reaction => {
		reaction.users.remove(msg.author);
		switch (reaction.emoji.name) {
			case emojiList[0]:
				page = page > 0 ? page -= 1 : pages.length - 1;
				break;
			case emojiList[1]:
				page = page + 1 < pages.length ? page += 1 : 0;
				break;
			default:
				break;
		}
		curPage.edit({ embeds: [pages[page].setFooter(`Page ${page + 1} / ${pages.length}`)] });
	});
	reactionCollector.on('end', () => {
		if (!curPage.deleted) {
			curPage.reactions.removeAll()
		}
	});
	return curPage;
};
module.exports = paginationEmbed;

DudeThatsErin avatar Jul 20 '21 16:07 DudeThatsErin

curPage.edit({embeds: [pages[page].setFooter(Page ${page + 1} / ${pages.length})]);

Rohit3523 avatar Aug 02 '21 09:08 Rohit3523

curPage.edit({embeds: [pages[page].setFooter(Page ${page + 1} / ${pages.length})]);

I see now. Yeah, I see I messed that up. I'll update that.

DudeThatsErin avatar Aug 06 '21 19:08 DudeThatsErin

FIXED if anyone else has the issue... copy and paste this to the index.js created by discord.js-pagination... 100% works.

const paginationEmbed = async (msg, pages, emojiList = ['⏪', '⏩'], timeout = 120000) => {
	if (!msg && !msg.channel) throw new Error('Channel is inaccessible.');
	if (!pages) throw new Error('Pages are not given.');
	if (emojiList.length !== 2) throw new Error('Need two emojis.');
	let page = 0;
	const curPage = await msg.channel.send({ embeds: [pages[page].setFooter(`Page ${page + 1} / ${pages.length}`)] });
	for (const emoji of emojiList) await curPage.react(emoji);
	const reactionCollector = curPage.createReactionCollector(
		(reaction, user) => emojiList.includes(reaction.emoji.name) && !user.bot,
		{ time: timeout }
	);
	reactionCollector.on('collect', reaction => {
		reaction.users.remove(msg.author);
		switch (reaction.emoji.name) {
			case emojiList[0]:
				page = page > 0 ? page -= 1 : pages.length - 1;
				break;
			case emojiList[1]:
				page = page + 1 < pages.length ? page += 1 : 0;
				break;
			default:
				break;
		}
		curPage.edit({ embeds: [pages[page].setFooter(`Page ${page + 1} / ${pages.length}`)] });
	});
	reactionCollector.on('end', () => {
		if (!curPage.deleted) {
			curPage.reactions.removeAll()
		}
	});
	return curPage;
};
module.exports = paginationEmbed;

when using this updated code, the bot would count itself as a react-able user. here is the working code:

const paginationEmbed = async (msg, pages, emojiList = ['⏪', '⏩'], timeout = 120000) => {
	var complete;
	let emojiDone = 0;
	if (!msg && !msg.channel) throw new Error('Channel is inaccessible.');
	if (!pages) throw new Error('Pages are not given.');
	if (emojiList.length !== 2) throw new Error('Need two emojis.');
	let page = 0;
	const curPage = await msg.channel.send({ embeds: [pages[page].setFooter(`Page ${page + 1} / ${pages.length}`)] });
	for (const emoji of emojiList) await curPage.react(emoji).then(emojiDone ++)

	if(emojiDone === 2){
		complete = true
	}
	if(complete === true){

	const reactionCollector = curPage.createReactionCollector(
		(reaction, user) => emojiList.includes(reaction.emoji.name) && !bot.user && !user === bot.user,
		{ time: timeout }
	);
   
	reactionCollector.on('collect', (reaction, user) => {
		if(!user.bot){

		reaction.users.remove(msg.author);
		switch (reaction.emoji.name) {
			case emojiList[0]:
				page = page > 0 ? page -= 1 : pages.length - 1;
				break;
			case emojiList[1]:
				page = page + 1 < pages.length ? page += 1 : 0;
				break;
			default:
				break;
		}
		curPage.edit({ embeds: [pages[page].setFooter(`Page ${page + 1} / ${pages.length}`)] });
		}
	
	});
	reactionCollector.on('end', () => {
		if (!curPage.deleted) {
			curPage.reactions.removeAll()
		}
	});

	return curPage;
}
};
module.exports = paginationEmbed;

veronancy avatar Nov 13 '21 11:11 veronancy