Skip to content

Fix unknown messages errors. #36

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 28 additions & 27 deletions src/FindEmoji.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ const { EmbedBuilder, ActionRowBuilder } = require('discord.js');
const { disableButtons, shuffleArray, formatMessage, ButtonBuilder } = require('../utils/utils');
const events = require('events');


module.exports = class FindEmoji extends events {
constructor(options = {}) {

Expand Down Expand Up @@ -56,8 +55,8 @@ module.exports = class FindEmoji extends events {


async sendMessage(content) {
if (this.options.isSlashGame) return await this.message.editReply(content);
else return await this.message.channel.send(content);
if (this.options.isSlashGame) return await this.message.editReply(content).catch(e => {});
else return await this.message.channel.send(content).catch(e => {});
}


Expand All @@ -78,32 +77,34 @@ module.exports = class FindEmoji extends events {
.setDescription(this.options.embed.description)
.setFooter({ text: this.message.author.tag, iconURL: this.message.author.displayAvatarURL({ dynamic: true }) });
const msg = await this.sendMessage({ embeds: [embed], components: this.getComponents(true) });


setTimeout(async () => {
embed.setDescription(this.options.embed.findDescription.replace('{emoji}', this.emoji));
await msg.edit({ embeds: [embed], components: this.getComponents(false) });
const collector = msg.createMessageComponentCollector({ idle: this.options.timeoutTime });


collector.on('collect', async (btn) => {
await btn.deferUpdate().catch(e => {});
if (btn.user.id !== this.message.author.id) {
if (this.options.playerOnlyMessage) btn.followUp({ content: formatMessage(this.options, 'playerOnlyMessage'), ephemeral: true });
return;
}
this.selected = this.emojis[parseInt(btn.customId.split('_')[1])];
return collector.stop();
})


collector.on('end', async (_, reason) => {
if (reason === 'idle' || reason === 'user') return this.gameOver(msg, (reason === 'user'));
})
}, this.options.hideEmojiTime);
const collector = msg.createMessageComponentCollector({ idle: this.options.hideEmojiTime });

collector.on('end', async (_, reason) => {
if (reason === 'messageDelete' || reason === 'channelDelete') return;

if (reason === 'idle') {
embed.setDescription(this.options.embed.findDescription.replace('{emoji}', this.emoji));
await msg.edit({ embeds: [embed], components: this.getComponents(false) });
const collector = msg.createMessageComponentCollector({ idle: this.options.timeoutTime });

collector.on('collect', async (btn) => {
await btn.deferUpdate().catch(e => {});
if (btn.user.id !== this.message.author.id) {
if (this.options.playerOnlyMessage) btn.followUp({ content: formatMessage(this.options, 'playerOnlyMessage'), ephemeral: true });
return;
}
this.selected = this.emojis[parseInt(btn.customId.split('_')[1])];
return collector.stop();
})


collector.on('end', async (_, reason) => {
if (reason === 'idle' || reason === 'user') return this.gameOver(msg, (reason === 'user'));
})
}
})
}


gameOver(msg, result) {
const FindEmojiGame = { player: this.message.author, selectedEmoji: this.selected, correctEmoji: this.emoji };
const resultMessage = result ? ((this.selected === this.emoji) ? 'win' : 'lose') : 'timeout';
Expand Down
1 change: 1 addition & 0 deletions utils/approve.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ module.exports = class Approve extends events {
})

collector.on('end', async (_, reason) => {
if (reason === 'messageDelete' || reason === 'channelDelete') return;
if (reason === 'accept') return resolve(msg);

const embed = new EmbedBuilder()
Expand Down