[javascript] Test
Viewer
*** This page was generated with the meta tag "noindex, nofollow". This happened because you selected this option before saving or the system detected it as spam. This means that this page will never get into the search engines and the search bot will not crawl it. There is nothing to worry about, you can still share it with anyone.
- const { setTimeout } = require('node:timers/promises')
- const randomChar = require('anime-character-random')
- const { EmbedBuilder, ActionRowBuilder, SelectMenuBuilder, ComponentType } = require('discord.js')
- const AnimeGuessListSchema = require('../../schemas/AnimeGuessSchema');
- const mongoose = require('mongoose');
- module.exports = {
- name: 'guess-anime-character',
- description: 'Guess the anime character from the image!',
- // devOnly: Boolean,
- testOnly: true,
- // options: Object[],
- //deleted: true,
- callback: async (client, interaction) => {
- await interaction.reply('Working on it');
- async function myFunction() {
- const AnimeData = await randomChar.GetChar()
- const db = [AnimeData.OtherCharacterList[0], AnimeData.OtherCharacterList[1], AnimeData.OtherCharacterList[2], AnimeData.CharacterName]
- const list = db.sort(() => Math.random() - 0.5)
- const embed = new EmbedBuilder()
- .setTitle('Guess the anime character')
- .setAuthor({ name: interaction.user.username.toString(), iconURL: interaction.guild.iconURL() })
- .setDescription(`Anime Name : ${AnimeData.AnimeName}`)
- .setColor('Red')
- .setFooter({ text: 'Cziju || Guess The Anime Character', iconURL: client.user.avatarURL() })
- .setTimestamp()
- .setImage(AnimeData.CharacterImage)
- const row = new ActionRowBuilder()
- .addComponents(
- new SelectMenuBuilder()
- .setCustomId('select')
- .setPlaceholder('Select an Answer')
- .addOptions(
- {
- label: list[0],
- description: 'Choose The Correct Answer',
- value: list[0]
- },
- {
- label: list[1],
- description: 'Choose The Correct Answer',
- value: list[1]
- },
- {
- label: list[2],
- description: 'Choose The Correct Answer',
- value: list[2]
- },
- {
- label: list[3],
- description: 'Choose The Correct Answer',
- value: list[3]
- }
- )
- )
- await interaction.editReply({ content: 'You Have **30 Seconds** To answer', components: [row], embeds: [embed] })
- const filter = i => i.user.id === interaction.user.id
- const collector = interaction.channel.createMessageComponentCollector({ filter, componentType: ComponentType.SelectMenu, max: 1, time: 30000 })
- collector.on('collect', async i => {
- if (i.values[0] === AnimeData.CharacterName) {
- await interaction.editReply({ content: 'You have Answered **Correctly**', components: [] })
- let getUserProfile = await AnimeGuessListSchema.findOne({ guildId: interaction.guild.id });
- if (!getUserProfile) {
- getUserProfile = new AnimeGuessListSchema({
- _id: new mongoose.Types.ObjectId(),
- guildId: interaction.guild.id,
- memberId: interaction.member.id,
- points: 1
- });
- await getUserProfile.save();
- } else {
- console.log('USPESNO');
- getUserProfile.updateOne({ guildId: interaction.guild.id, memberId: interaction.user.id}, {
- $inc: {
- points: 100
- }
- })
- }
- } else {
- await interaction.editReply({ content: `You have Answered **Incorrectly**\n The correct answer is **${AnimeData.CharacterName}**`, components: [] })
- let getUserProfile = await AnimeGuessListSchema.findOne({ guildId: interaction.guild.id });
- if (!getUserProfile) {
- getUserProfile = new AnimeGuessListSchema({
- _id: new mongoose.Types.ObjectId(),
- guildId: interaction.guild.id,
- memberId: interaction.member.id,
- points: 1
- });
- await getUserProfile.save();
- } else {
- console.log('USPESNO');
- getUserProfile.updateOne({ guildId: interaction.guild.id, memberId: interaction.user.id}, {
- $inc: {
- points: 100
- }
- })
- }
- }
- })
- collector.on('end', async collected => {
- if (collected.size === 0) await interaction.editReply({ content: `🕛 Time's Up\n The correct answer is **${AnimeData.CharacterName}**`, components: [] })
- })
- }
- myFunction();
- },
- };
Editor
You can edit this paste and save as new: