Error handling -> Anime treatment to manga.

master
Cristiano Pires 1 year ago
parent af8fbeb9f0
commit 9331dcd4aa

@ -18,46 +18,34 @@ class manga extends Command{
if(!args[0]) return new ErrorMessage(this.client).send(ErrorType.Arguments, message) if(!args[0]) return new ErrorMessage(this.client).send(ErrorType.Arguments, message)
const data = await new aniList().searchManga(args.join(' ')); 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.`]) 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() // console.log('SearchManga: Data:', data)
.setTitle('First 4 results of search:') const embed = new EmbedBuilder();
.setAuthor({name:"Rem-chan", iconURL:"https://i.imgur.com/g6FSNhL.png",url:'https://rem.wordfights.com/addtodiscord'}) const randomID = Random();
.setColor(0x003284) const row = new ActionRowBuilder();
.setURL('https://www.rem.wordfights.com') var fieldPayload = [];
.setFooter({ text: 'Rem-Chan on', iconURL: 'https://i.imgur.com/g6FSNhL.png' }) var embeds = [];
.setImage(data[0].image) for(var i = 0; i<data.length; i++)
.setTimestamp() {
.addFields( fieldPayload.push({name:data[i].title.romaji+(data[i].title.english?"("+data[i].title.english+")":''), value:i.toString()});
{name:data[0].title.romaji+(data[0].title.english?"("+data.title.english+")":''), value:'1'}, embeds.push(new EmbedBuilder().setImage(data[i].image).setURL('https://www.rem.wordfights.com'));
{name:data[1].title.romaji+(data[1].title.english?"("+data.title.english+")":''), value:'2'}, row.addComponents(
{name:data[2].title.romaji+(data[2].title.english?"("+data.title.english+")":''), value:'3'}, new ButtonBuilder()
{name:data[3].title.romaji+(data[3].title.english?"("+data.title.english+")":''), value:'4'}, .setCustomId(randomID+i)
.setLabel(i.toString())
.setStyle(ButtonStyle.Success)
); );
var embeds = [embed] }
embeds.push(new EmbedBuilder().setImage(data[1].image).setURL('https://www.rem.wordfights.com'));
embeds.push(new EmbedBuilder().setImage(data[2].image).setURL('https://www.rem.wordfights.com'));
embeds.push(new EmbedBuilder().setImage(data[3].image).setURL('https://www.rem.wordfights.com'));
const randomID = Random(); embed.setTitle(`First ${data.length>=4?'4':data.length} results of search:`)
const row = new ActionRowBuilder() .setAuthor({name:"Rem-chan", iconURL:"https://i.imgur.com/g6FSNhL.png",url:'https://rem.wordfights.com/addtodiscord'})
.addComponents( .setColor(0x003284)
new ButtonBuilder() .setURL('https://www.rem.wordfights.com')
.setCustomId(randomID+1) .setFooter({ text: 'Rem-Chan on', iconURL: 'https://i.imgur.com/g6FSNhL.png' })
.setLabel('1') .setTimestamp()
.setStyle(ButtonStyle.Success), .addFields(fieldPayload);
new ButtonBuilder()
.setCustomId(randomID+2) embeds.unshift(embed);
.setLabel('2')
.setStyle(ButtonStyle.Success),
new ButtonBuilder()
.setCustomId(randomID+3)
.setLabel('3')
.setStyle(ButtonStyle.Success),
new ButtonBuilder()
.setCustomId(randomID+4)
.setLabel('4')
.setStyle(ButtonStyle.Success),
);
const filter = i => i.customId.slice(0,-1) === randomID; const filter = i => i.customId.slice(0,-1) === randomID;
await message.channel.send({ephemeral: true, embeds, components: [row] }); await message.channel.send({ephemeral: true, embeds, components: [row] });
const collector = message.channel.createMessageComponentCollector({ filter, time: 60000 }); const collector = message.channel.createMessageComponentCollector({ filter, time: 60000 });

Loading…
Cancel
Save