diff --git a/commands/admin/activateStrikes.js b/commands/admin/activateStrikes.js index 81a7deb..085983a 100644 --- a/commands/admin/activateStrikes.js +++ b/commands/admin/activateStrikes.js @@ -42,7 +42,7 @@ module.exports = class leave extends Command .setLabel('Remove this.') .setStyle(ButtonStyle.Primary), ); - await message.channel.send({ephemeral: true, embeds: [embed], components: [row] }); + const Message = await message.channel.send({ephemeral: true, embeds: [embed], components: [row] }); const filter = i => i.customId === randomID; const collector = message.channel.createMessageComponentCollector({ filter, time: 60000 }); @@ -52,6 +52,10 @@ module.exports = class leave extends Command message.delete(); m.message.delete(); }); + collector.on('end', async ()=> + { + this.client.guilds.cache.get(Message.guildId).channels.cache.get(Message.channelId).messages.cache.get(Message.id).edit({ components: [] }); + }) } } } \ No newline at end of file diff --git a/commands/admin/createchannel.js b/commands/admin/createchannel.js index e7e87c8..9d6e39b 100644 --- a/commands/admin/createchannel.js +++ b/commands/admin/createchannel.js @@ -49,7 +49,7 @@ const {EmbedBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle, ChannelType, .setLabel('Remove this.') .setStyle(ButtonStyle.Primary), ); - await message.channel.send({ephemeral: true, embeds: [embed], components: [row] }); + const Message = await message.channel.send({ephemeral: true, embeds: [embed], components: [row] }); const filter = i => i.customId === randomID; const collector = message.channel.createMessageComponentCollector({ filter, time: 60000 }); @@ -60,7 +60,10 @@ const {EmbedBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle, ChannelType, m.message.delete(); }); - + collector.on('end', async ()=> + { + this.client.guilds.cache.get(Message.guildId).channels.cache.get(Message.channelId).messages.cache.get(Message.id).edit({ components: [] }); + }) } } }module.exports = createchannel; \ No newline at end of file diff --git a/commands/admin/createvoicechannel.js b/commands/admin/createvoicechannel.js index a38627a..c3ba06a 100644 --- a/commands/admin/createvoicechannel.js +++ b/commands/admin/createvoicechannel.js @@ -60,7 +60,7 @@ const {EmbedBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle, ChannelType, .setStyle(ButtonStyle.Primary) ); - await message.channel.send({ + const Message = await message.channel.send({ ephemeral: true, embeds: [embed], components: [row] @@ -77,6 +77,10 @@ const {EmbedBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle, ChannelType, message.delete(); m.message.delete(); }); + collector.on('end', async ()=> + { + this.client.guilds.cache.get(Message.guildId).channels.cache.get(Message.channelId).messages.cache.get(Message.id).edit({ components: [] }); + }) } } diff --git a/commands/admin/guilds.js b/commands/admin/guilds.js index fbc80dc..c1acc5b 100644 --- a/commands/admin/guilds.js +++ b/commands/admin/guilds.js @@ -42,7 +42,7 @@ class Guilds extends Command .setLabel('Remove this.') .setStyle(ButtonStyle.Primary), ); - await message.channel.send({ephemeral: true, embeds: payload.embeds, components: [row] }); + const Mesage = await message.channel.send({ephemeral: true, embeds: payload.embeds, components: [row] }); const filter = i => i.customId === costumID; const collector = message.channel.createMessageComponentCollector({ filter, time: 60000 }); @@ -52,7 +52,10 @@ class Guilds extends Command message.delete(); m.message.delete(); }); - + collector.on('end', async ()=> + { + this.client.guilds.cache.get(Message.guildId).channels.cache.get(Message.channelId).messages.cache.get(Message.id).edit({ components: [] }); + }) } diff --git a/commands/admin/purge.js b/commands/admin/purge.js index 8e36bc9..57b32e1 100644 --- a/commands/admin/purge.js +++ b/commands/admin/purge.js @@ -66,7 +66,7 @@ const {Command} = require('../../lib.js') .setLabel('Remove this.') .setStyle(ButtonStyle.Primary), ); - await message.channel.send({ephemeral: true, embeds: [embed], components: [row] }); + const Message = await message.channel.send({ephemeral: true, embeds: [embed], components: [row] }); const filter = i => i.customId === costumID; const collector = message.channel.createMessageComponentCollector({ filter, time: 60000 }); @@ -76,5 +76,9 @@ const {Command} = require('../../lib.js') message.delete(); m.message.delete(); }); + collector.on('end', async ()=> + { + this.client.guilds.cache.get(Message.guildId).channels.cache.get(Message.channelId).messages.cache.get(Message.id).edit({ components: [] }); + }) } }module.exports = purge; diff --git a/commands/admin/removerustcommitschannel.js b/commands/admin/removerustcommitschannel.js index b298488..7a0e00b 100644 --- a/commands/admin/removerustcommitschannel.js +++ b/commands/admin/removerustcommitschannel.js @@ -56,7 +56,7 @@ const {Command, } = require('../../lib.js'); .setStyle(ButtonStyle.Primary), ); embed.addFields({name:success?'Removed':'Error', value:success?'Successfully removed from the list.':error}) - await message.channel.send({ephemeral: true, embeds: [embed], components: [row] }); + const Message = await message.channel.send({ephemeral: true, embeds: [embed], components: [row] }); const filter = i => i.customId === 'RemoveUnsetRustCommitsChannel'; @@ -67,6 +67,10 @@ const {Command, } = require('../../lib.js'); message.delete(); m.message.delete() }); + collector.on('end', async ()=> + { + this.client.guilds.cache.get(Message.guildId).channels.cache.get(Message.channelId).messages.cache.get(Message.id).edit({ components: [] }); + }) } } diff --git a/commands/admin/setFreeGamesChannel.js b/commands/admin/setFreeGamesChannel.js index 33eb2ff..424073a 100644 --- a/commands/admin/setFreeGamesChannel.js +++ b/commands/admin/setFreeGamesChannel.js @@ -64,13 +64,17 @@ class setfreegameschannel extends Command{ ); const filter = i => i.customId === 'RemoveRustCommitsNewChannelMessage'; - await message.channel.send({ephemeral: true, embeds: [embed], components: [row] }); + const Message = await message.channel.send({ephemeral: true, embeds: [embed], components: [row] }); const collector = message.channel.createMessageComponentCollector({ filter, time: 60000 }); collector.on('collect', async m => { message.delete(); m.message.delete() }); + collector.on('end', async ()=> + { + this.client.guilds.cache.get(Message.guildId).channels.cache.get(Message.channelId).messages.cache.get(Message.id).edit({ components: [] }); + }) } function addChannel(id, name) { diff --git a/commands/admin/setrustcommitschannel.js b/commands/admin/setrustcommitschannel.js index 2b4f826..b83c592 100644 --- a/commands/admin/setrustcommitschannel.js +++ b/commands/admin/setrustcommitschannel.js @@ -39,13 +39,17 @@ class setrustcommitschannel extends Command{ ); const filter = i => i.customId === 'RemoveRustCommitsNewChannelMessage'; - await message.channel.send({ephemeral: true, embeds: [embed], components: [row] }); + const Mesage = await message.channel.send({ephemeral: true, embeds: [embed], components: [row] }); const collector = message.channel.createMessageComponentCollector({ filter, time: 60000 }); collector.on('collect', async m => { message.delete(); m.message.delete() }); + collector.on('end', async ()=> + { + this.client.guilds.cache.get(Message.guildId).channels.cache.get(Message.channelId).messages.cache.get(Message.id).edit({ components: [] }); + }) } function addChannel(id, name) { diff --git a/commands/admin/strike.js b/commands/admin/strike.js index cd9bc40..61b5284 100644 --- a/commands/admin/strike.js +++ b/commands/admin/strike.js @@ -55,7 +55,7 @@ const strikeM = require('../../models/strikes'); ); const filter = i => i.customId === 'RemoveStrikeMessage'; - await this.message.channel.send({ephemeral: true, embeds: [embed], components: [row] }); + const Message = await this.message.channel.send({ephemeral: true, embeds: [embed], components: [row] }); const collector = this.message.channel.createMessageComponentCollector({ filter, time: 60000 }); collector.on('collect', async m => { @@ -69,6 +69,10 @@ const strikeM = require('../../models/strikes'); // console.log('Strikes: Embed Message: failed to delete.'); }) }); + collector.on('end', async ()=> + { + this.client.guilds.cache.get(Message.guildId).channels.cache.get(Message.channelId).messages.cache.get(Message.id).edit({ components: [] }); + }) } async confirmArgs(message,args) { diff --git a/commands/music/activateMusic.js b/commands/music/activateMusic.js index be2bfe8..249624c 100644 --- a/commands/music/activateMusic.js +++ b/commands/music/activateMusic.js @@ -43,7 +43,7 @@ module.exports = class leave extends Command .setLabel('Remove this.') .setStyle(ButtonStyle.Primary), ); - await message.channel.send({ephemeral: true, embeds: [embed], components: [row] }); + const Message = await message.channel.send({ephemeral: true, embeds: [embed], components: [row] }); const filter = i => i.customId === randomID; const collector = message.channel.createMessageComponentCollector({ filter, time: 60000 }); @@ -53,6 +53,10 @@ module.exports = class leave extends Command message.delete(); m.message.delete(); }); + collector.on('end', async ()=> + { + this.client.guilds.cache.get(Message.guildId).channels.cache.get(Message.channelId).messages.cache.get(Message.id).edit({ components: [] }); + }) } } } \ No newline at end of file diff --git a/commands/music/play.js b/commands/music/play.js index b057a94..3884e72 100644 --- a/commands/music/play.js +++ b/commands/music/play.js @@ -113,7 +113,7 @@ module.exports = class play extends Command .setLabel(` X `) .setStyle(ButtonStyle.Danger), ); - await message.channel.send({ephemeral: true, embeds: [embed], components: [row] }); + const Message = await message.channel.send({ephemeral: true, embeds: [embed], components: [row] }); const filter = i => i.customId.startsWith(`${randomID}PlayUserChoice`); const collector = message.channel.createMessageComponentCollector({ filter, time: 60000 }); @@ -127,6 +127,10 @@ module.exports = class play extends Command addToQ(videos[parseInt(m.customId.split(`${randomID}PlayUserChoice`)[1])]) } }); + collector.on('end', async ()=> + { + this.client.guilds.cache.get(Message.guildId).channels.cache.get(Message.channelId).messages.cache.get(Message.id).edit({ components: [] }); + }) } } diff --git a/commands/search/searchAnime.js b/commands/search/searchAnime.js index b00e1ab..ffbce76 100644 --- a/commands/search/searchAnime.js +++ b/commands/search/searchAnime.js @@ -15,7 +15,7 @@ class anime extends Command{ }) } async run(message, args){ - if(!args[0]) return new ErrorMessage(this.client).send(ErrorType.Arguments, message) + if(!args[0]) return new ErrorMessage(this.client).send(ErrorType.NoArguments, message) const data = await new Anilist().searchAnime(args.join(' ')); if(data=='Error') return new ErrorMessage(this.client).send(ErrorType.Arguments, message, [`Couldn't find any anime with the search argument you provided.`]) // console.log('SearchAnime: Data:', data[1].title.romaji, data.length); @@ -50,18 +50,22 @@ class anime extends Command{ .setTimestamp() .addFields(fieldPayload); const filter = i => i.customId.slice(0,-1) === randomID; - await message.channel.send({ephemeral: true, embeds, components: [row] }); + const Message = await message.channel.send({ephemeral: true, embeds, components: [row] }); const collector = message.channel.createMessageComponentCollector({ filter, time: 60000 }); collector.on('collect', async m => { message.delete(); m.message.delete(); - if(m.customId[m.customId.length-1]!=4) sendMessage(data[m.customId[m.customId.length-1]].id); + if(m.customId[m.customId.length-1]!=4) sendMessage(data[m.customId[m.customId.length-1]].id, this.client); }); + collector.on('end', async ()=> + { + this.client.guilds.cache.get(Message.guildId).channels.cache.get(Message.channelId).messages.cache.get(Message.id).edit({ components: [] }); + }) /** * @param {Number} id */ - async function sendMessage(id) + async function sendMessage(id, client) { const data = await new Anilist().getAnimeInfo(id); // console.log('Command: SearchChar: SendMessage: Data', data) @@ -106,6 +110,10 @@ class anime extends Command{ { m.message.delete(); }); + collector.on('end', async ()=> + { + client.guilds.cache.get(sentMessage.guildId).channels.cache.get(sentMessage.channelId).messages.cache.get(sentMessage.id).edit({ components: [] }); + }) } } diff --git a/commands/search/searchChar.js b/commands/search/searchChar.js index 1fd0d85..7a2f2b3 100644 --- a/commands/search/searchChar.js +++ b/commands/search/searchChar.js @@ -15,7 +15,7 @@ class char extends Command{ } async run(message, args) { - if(!args[0]) return new ErrorMessage(this.client).send(ErrorType.Arguments, message) + if(!args[0]) return new ErrorMessage(this.client).send(ErrorType.NoArguments, message) const data = await new Anilist().searchChar(args.join(' ')); if(data=='Error') return new ErrorMessage(this.client).send(ErrorType.Arguments, message, [`Couldn't find any character with the search argument you provided.`]) const embed = new EmbedBuilder(); @@ -51,18 +51,22 @@ class char extends Command{ // console.log(data.length, embeds.length, embeds) const filter = i => i.customId.slice(0,-1) === randomID; - await message.channel.send({ephemeral: true, embeds, components: [row] }); + const sentMessage = await message.channel.send({ephemeral: true, embeds, components: [row] }); const collector = message.channel.createMessageComponentCollector({ filter, time: 60000 }); collector.on('collect', async m => { message.delete(); m.message.delete(); - if(m.customId[m.customId.length-1]!=4) sendMessage(data[m.customId[m.customId.length-1]].id); + if(m.customId[m.customId.length-1]!=4) sendMessage(data[m.customId[m.customId.length-1]].id, this.client); }); + collector.on('end', async ()=> + { + this.client.guilds.cache.get(sentMessage.guildId).channels.cache.get(sentMessage.channelId).messages.cache.get(sentMessage.id).edit({ components: [] }); + }) /** * @param {Number} id */ - async function sendMessage(id) + async function sendMessage(id, client) { const data = await new Anilist().getCharInfo(id); data.description = data.description.replaceAll('~!', '').replaceAll('!~', '').replaceAll(/<[^>]*>/g, ''); @@ -80,18 +84,9 @@ class char extends Command{ .addFields( {name:'Page', value:data.url, inline:true} ); - if(data.age) - { - embed.addFields({name:'Age:',value:data.age, inline:true}); - } - if(data.gender) - { - embed.addFields({name:'Gender:', value:data.gender?data.gender:'', inline:true},); - } - if(!data.name.native) - { - embed.setTitle(`${data.name.full}`) - } + if(data.age) embed.addFields({name:'Age:',value:data.age, inline:true}); + if(data.gender) embed.addFields({name:'Gender:', value:data.gender?data.gender:'', inline:true},); + if(!data.name.native) embed.setTitle(`${data.name.full}`) const randomID = Random(); const row = new ActionRowBuilder() .addComponents( @@ -107,6 +102,10 @@ class char extends Command{ { m.message.delete(); }); + collector.on('end', async ()=> + { + client.guilds.cache.get(sentMessage.guildId).channels.cache.get(sentMessage.channelId).messages.cache.get(sentMessage.id).edit({ components: [] }); + }) } } diff --git a/commands/search/searchManga.js b/commands/search/searchManga.js index 2c3dec1..6852490 100644 --- a/commands/search/searchManga.js +++ b/commands/search/searchManga.js @@ -15,85 +15,93 @@ class manga extends Command{ } async run(message, args) { - if(!args[0]) return new ErrorMessage(this.client).send(ErrorType.Arguments, message) - const data = await new Anilist().searchManga(args.join(' ')); - if(data=='Error') return new ErrorMessage(this.client).send(ErrorType.Arguments, message, [`Couldn't find any character with the search argument you provided.`]) - // console.log('SearchManga: Data:', data) - const embed = new EmbedBuilder(); - const randomID = Random(); - const row = new ActionRowBuilder(); - var fieldPayload = []; - var embeds = []; - for(var i = 0; i=4?'4':(data.length + ' and only')} result${data.length>1?'s':''} of search:`) - .setAuthor({name:"Rem-chan", iconURL:"https://i.imgur.com/g6FSNhL.png",url:'https://rem.wordfights.com/addtodiscord'}) - .setColor(0x003284) - .setURL('https://www.rem.wordfights.com') - .setFooter({ text: 'Rem-Chan on', iconURL: 'https://i.imgur.com/g6FSNhL.png' }) - .setTimestamp() - .addFields(fieldPayload); + .setCustomId(randomID+i) + .setLabel(i.toString()) + .setStyle(ButtonStyle.Success) + ); + } + row.addComponents( + new ButtonBuilder() + .setCustomId(randomID+4) + .setLabel('Cancel') + .setStyle(ButtonStyle.Danger) + ) + embed.setTitle(`First ${data.length>=4?'4':(data.length + ' and only')} result${data.length>1?'s':''} of search:`) + .setAuthor({name:"Rem-chan", iconURL:"https://i.imgur.com/g6FSNhL.png",url:'https://rem.wordfights.com/addtodiscord'}) + .setColor(0x003284) + .setURL('https://www.rem.wordfights.com') + .setFooter({ text: 'Rem-Chan on', iconURL: 'https://i.imgur.com/g6FSNhL.png' }) + .setTimestamp() + .addFields(fieldPayload); - embeds.unshift(embed); + embeds.unshift(embed); - const filter = i => i.customId.slice(0,-1) === randomID; - await message.channel.send({ephemeral: true, embeds, components: [row] }); + const filter = i => i.customId.slice(0,-1) === randomID; + const Message = await message.channel.send({ephemeral: true, embeds, components: [row] }); + const collector = message.channel.createMessageComponentCollector({ filter, time: 60000 }); + collector.on('collect', async m => + { + message.delete(); + m.message.delete(); + if(m.customId[m.customId.length-1]!=4) sendMessage(data[m.customId[m.customId.length-1]].id, this.client); + }); + collector.on('end', async ()=> + { + this.client.guilds.cache.get(Message.guildId).channels.cache.get(Message.channelId).messages.cache.get(Message.id).edit({ components: [] }); + }) + /** + * @param {Number} id + */ + async function sendMessage(id, client) + { + const data = await new Anilist().getMangaInfo(id); + data.description = data.description.replaceAll('~!', '').replaceAll('!~', '').replaceAll(/<[^>]*>/g, ''); + data.description = data.description.length>1500?(data.description.substring(0, 1500) + "..."):data.description; + console.log(data.description) + const embed = new EmbedBuilder() + .setTitle(`${data.title.romaji} (${data.title.native + (data.title.english?'/'+data.title.english:'')})`) + .setAuthor({name:"Rem-chan", iconURL:"https://i.imgur.com/g6FSNhL.png",url:'https://rem.wordfights.com/addtodiscord'}) + .setColor(0x003284) + .setDescription(data.description) + .setFooter({ text: 'Rem-Chan on', iconURL: 'https://i.imgur.com/g6FSNhL.png' }) + .addFields({name:'Page', value:data.url, inline:true}) + .setImage(data.coverImage) + .setThumbnail(data.coverImage) + .setTimestamp() + const randomID = Random(); + const row = new ActionRowBuilder() + .addComponents( + new ButtonBuilder() + .setCustomId(randomID) + .setLabel('Remove this.') + .setStyle(ButtonStyle.Primary), + ); + const filter = i => i.customId === randomID; + const sentMessage = await message.channel.send({ephemeral: true, embeds: [embed], components: [row] }); const collector = message.channel.createMessageComponentCollector({ filter, time: 60000 }); collector.on('collect', async m => { - message.delete(); m.message.delete(); - if(m.customId[m.customId.length-1]!=4) sendMessage(data[m.customId[m.customId.length-1]].id); - }); - /** - * @param {Number} id - */ - async function sendMessage(id) + }); + collector.on('end', async ()=> { - const data = await new Anilist().getMangaInfo(id); - data.description = data.description.replaceAll('~!', '').replaceAll('!~', '').replaceAll(/<[^>]*>/g, ''); - data.description = data.description.length>1500?(data.description.substring(0, 1500) + "..."):data.description; - console.log(data.description) - const embed = new EmbedBuilder() - .setTitle(`${data.title.romaji} (${data.title.native + (data.title.english?'/'+data.title.english:'')})`) - .setAuthor({name:"Rem-chan", iconURL:"https://i.imgur.com/g6FSNhL.png",url:'https://rem.wordfights.com/addtodiscord'}) - .setColor(0x003284) - .setDescription(data.description) - .setFooter({ text: 'Rem-Chan on', iconURL: 'https://i.imgur.com/g6FSNhL.png' }) - .addFields({name:'Page', value:data.url, inline:true}) - .setImage(data.coverImage) - .setThumbnail(data.coverImage) - .setTimestamp() - const randomID = Random(); - const row = new ActionRowBuilder() - .addComponents( - new ButtonBuilder() - .setCustomId(randomID) - .setLabel('Remove this.') - .setStyle(ButtonStyle.Primary), - ); - const filter = i => i.customId === randomID; - await message.channel.send({ephemeral: true, embeds: [embed], components: [row] }); - const collector = message.channel.createMessageComponentCollector({ filter, time: 60000 }); - collector.on('collect', async m => - { - m.message.delete(); - }); - } + client.guilds.cache.get(sentMessage.guildId).channels.cache.get(sentMessage.channelId).messages.cache.get(sentMessage.id).edit({ components: [] }); + }) + } } }module.exports = manga; diff --git a/lib.js b/lib.js index edb090e..cd04030 100644 --- a/lib.js +++ b/lib.js @@ -515,7 +515,7 @@ class ErrorMessage .setStyle(ButtonStyle.Primary) .setEmoji('❌') ); - await this.client.channels.cache.get(message.channel.id).send({ephemeral: true, embeds: [embed], components: [row] }); + const Message = await this.client.channels.cache.get(message.channel.id).send({ephemeral: true, embeds: [embed], components: [row] }); const filter = i => i.customId === randomID; @@ -526,6 +526,11 @@ class ErrorMessage message.delete().then(()=>m.message.delete()) .catch(()=>m.message.delete()); }); + collector.on('end', async ()=> + { + this.client.guilds.cache.get(Message.guildId).channels.cache.get(Message.channelId).messages.cache.get(Message.id).edit({ components: [] }); + }) + } }module.exports.ErrorMessage = ErrorMessage;