diff --git a/commands/fetch/fetch.js b/commands/fetch/fetch.js index 9b46748..c62ea39 100644 --- a/commands/fetch/fetch.js +++ b/commands/fetch/fetch.js @@ -7,23 +7,43 @@ module.exports = { .addUserOption(option => option.setName('user').setDescription('User to fetch messages from').setRequired(true)), async execute(interaction) { const target = interaction.options.getUser('user'); + let targetId; + const deathMessages = []; + await interaction.deferReply(); - console.log(target); + await interaction.guild.members.fetch(target, { force: true }) - .then((member) => { - targetId = member.id; - }) + .then(member => targetId = member.id) .catch(error => console.error(`error. ${error}`)); - await interaction.channel.messages.fetch() - .then((messages) => { - messages.filter(message => message.author.id === targetId); - console.log(messages); - for (message in messages) { - console.log(message); - console.log(message.content); + + const channel = interaction.client.channels.cache.get(interaction.channel.id); + + let deathMessage = await channel.messages + .fetch({ limit: 1 }) + .then(messagePage => (messagePage.size === 1 ? messagePage.at(0) : null)); + + while (deathMessage) { + await channel.messages + .fetch({ limit: 100, before: deathMessage.id }) + .then(messagePage => { + messagePage.forEach((msg) => { + if (msg.author.id === targetId) deathMessages.push(msg.content); + }); + deathMessage = messagePage.size > 0 ? messagePage.at(messagePage.size - 1) : null; + }); + } + + if (!deathMessages) { + await interaction.editReply('There Are No Messages'); + } + else { + deathMessages.forEach((death) => { + if (!death.match('joined') || !death.match('left')) { + console.log(death); } - }) - .catch(console.error); - await interaction.editReply(targetId); + }); + // console.log(deathMessages); + await interaction.editReply(`(${deathMessages.length})Death Messages Founded!!! Check Console`); + } }, }; \ No newline at end of file