Quiz Command
Hello, I am presenting a Quiz Command.
Quiz is about choosing the correct character name in the image from 4 options (buttons).
It includes Anime, ONA, OVA, VN and even #-games (for which I can do nothing since the API I am using provides it as well).
This wiki also contains a leaderboard for the Quiz Command.
I used Command handler in the code(s) so if you don't use command handler and don't know what to do, message me in this discussion (thread).
Variables Required:
quizcharacter: "",
quizchannel: "",
quizmessage: "",
quizchance: "false",
quizanswer: "false",
quizscore: "0",
quizimage: "",
money: "0"
Note #1: if you have a different economy variable (for which in my case is money but if your is coin or dollar), please use that and replace the variable money in the code with your economy variable.
Note #2: Your bot must have the onInteractionCreate and onMesage event and messageContent intent (in your main file), and the scope applications.commands (when inviting it) or else the commands won't work.
Note #3: You must install aoi.parser and setup it or else the commands won't work.
Code:
module.exports = [{
name: "$alwaysExecute",
$if: "old",
code: `
$editMessage[$getGuildVar[quizmessage];
{newEmbed:
{title:Choose the correct name of the character!}
{image:$getGuildVar[quizimage]}
{footer: you have only one chance!
all the quiz are taken from animecharactersdatabase.com.}} $nonEscape[$get[random]]]
$let[random;$randomText[{actionRow:{button:$httpRequest[https://www.animecharactersdatabase.com/api_series_characters.php?character_id=$random[1;100000];GET;;name;Error Occured!]:1:correct}{button:$httpRequest[https://www.animecharactersdatabase.com/api_series_characters.php?character_id=$random[1;100000;false;true];GET;;name;Error Occured!]:1:wrong1}}{actionRow:{button:$httpRequest[https://www.animecharactersdatabase.com/api_series_characters.php?character_id=$random[1;100000;false;true];GET;;name;Error Occured!]:1:wrong2}{button:$httpRequest[https://www.animecharactersdatabase.com/api_series_characters.php?character_id=$random[1;100000;false;true];GET;;name;Error Occured!]:1:wrong3}};{actionRow:{button:$httpRequest[https://www.animecharactersdatabase.com/api_series_characters.php?character_id=$random[1;100000;false;true];GET;;name;Error Occured!]:1:wrong1}{button:$httpRequest[https://www.animecharactersdatabase.com/api_series_characters.php?character_id=$random[1;100000];GET;;name;Error Occured!]:1:correct}}{actionRow:{button:$httpRequest[https://www.animecharactersdatabase.com/api_series_characters.php?character_id=$random[1;100000;false;true];GET;;name;Error Occured!]:1:wrong2}{button:$httpRequest[https://www.animecharactersdatabase.com/api_series_characters.php?character_id=$random[1;100000;false;true];GET;;name;Error Occured!]:1:wrong3}};{actionRow:{button:$httpRequest[https://www.animecharactersdatabase.com/api_series_characters.php?character_id=$random[1;100000;false;true];GET;;name;Error Occured!]:1:wrong1}{button:$httpRequest[https://www.animecharactersdatabase.com/api_series_characters.php?character_id=$random[1;100000;false;true];GET;;name;Error Occured!]:1:wrong2}}{actionRow:{button:$httpRequest[https://www.animecharactersdatabase.com/api_series_characters.php?character_id=$random[1;100000];GET;;name;Error Occured!]:1:correct}{button:$httpRequest[https://www.animecharactersdatabase.com/api_series_characters.php?character_id=$random[1;100000;false;true];GET;;name;Error Occured!]:1:wrong3}};{actionRow:{button:$httpRequest[https://www.animecharactersdatabase.com/api_series_characters.php?character_id=$random[1;100000;false;true];GET;;name;Error Occured!]:1:wrong1}{button:$httpRequest[https://www.animecharactersdatabase.com/api_series_characters.php?character_id=$random[1;100000;false;true];GET;;name;Error Occured!]:1:wrong2}}{actionRow:{button:$httpRequest[https://www.animecharactersdatabase.com/api_series_characters.php?character_id=$random[1;100000;false;true];GET;;name;Error Occured!]:1:wrong3}{button:$httpRequest[https://www.animecharactersdatabase.com/api_series_characters.php?character_id=$random[1;100000];GET;;name;Error Occured!]:1:correct}}]]
$setGuildVar[quizimage;$httpRequest[https://www.animecharactersdatabase.com/api_series_characters.php?character_id=$random[1;100000];GET;;character_image;Error Occured!]]
$setGuildVar[quizcharacter;$httpRequest[https://www.animecharactersdatabase.com/api_series_characters.php?character_id=$random[1;100000];GET;;name;Error Occured!]]
$setGuildVar[quizmessage;$sendMessage[Generating Quiz....;true]]
$resetGuildVar[quizmessage]
$resetUserVar[quizchance]
$resetGuildVar[quizimage]
$resetGuildVar[quizchannel]
$resetGuildVar[quizcharacter]
$resetGuildVar[quizanswer]
$if[$getGuildVar[quizanswer]==false&&$getGuildVar[quizmessage]!=]
$editMessage[$getGuildVar[quizmessage];{newEmbed:{description: **This quiz has timed out!**}}]
$endif
$cooldown[3h]
`
}, {
name: "correct",
type: "interaction",
prototype: "button",
code: `
$interactionReply[***Correct!***
The name is **$getguildVar[quizcharacter]**!
Your score is **$getuservar[quizscore]**
You get **+2 money**;;;;everyone;true]
$editMessage[$getGuildVar[quizmessage];
{newEmbed:
{title: Answered!}
{description: This quiz has successfully been answered by **$userName**!
The answer is **_$getguildVar[quizcharacter]_**}}{newEmbed:
{title:Choose the correct name of the character!}
{image:$getGuildVar[quizimage]}
{footer:all the quiz are taken from animecharactersdatabase.com.}
}]
$setUserVar[quizscore;$sum[$getuservar[quizscore];1]]
$setUserVar[money;$sum[$getuservar[money];2]]
$setGuildVar[quizanswer;true]
$onlyif[$getUserVar[quizchance]!=true;Oops! You have already used your chance. {options:{ephemeral:true}} {extraOptions:{interaction:true}}]
`
}, {
name: "wrong1",
type: "interaction",
prototype: "button",
code: `
$interactionReply[Oops! It's wrong...;;;;everyone;true]
$setUserVar[quizchance;true]
$onlyif[$getUserVar[quizchance]!=true;Oops! You have already used your chance. {options:{ephemeral:true}} {extraOptions:{interaction:true}}]
`
}, {
name: "wrong2",
type: "interaction",
prototype: "button",
code: `
$interactionReply[Oops! It's wrong...;;;;everyone;true]
$setUserVar[quizchance;true]
$onlyif[$getUserVar[quizchance]!=true;Oops! You have already used your chance. {options:{ephemeral:true}} {extraOptions:{interaction:true}}]
`
}, {
name: "wrong3",
type: "interaction",
prototype: "button",
code: `
$interactionReply[Oops! It's wrong...;;;;everyone;true]
$setUserVar[quizchance;true]
$onlyif[$getUserVar[quizchance]!=true;Oops! You have already used your chance. {options:{ephemeral:true}} {extraOptions:{interaction:true}}]
`
}]
LeaderBoard (slash) command for the Quiz
First, make a slash command (you may use your eval command to make one or make a command for making slash commands)
Global (Note: Takes time to appear in command list)
$createApplicationCommand[global;leaderboard;shows the Quiz Leaderboard.;true;slash;[
{
"name": "hide",
"description": "Hide the leaderboard from others when using it.",
"type": 5
}
]]
Or, Guild only.
$createApplicationCommand[$guildID;leaderboard;shows the Quiz Leaderboard.;true;slash;[
{
"name": "hide",
"description": "Hide the leaderboard from others when using it.",
"type": 5
}
]]
Note #1: Your bot must have the onInteractionCreate event (in your main file) and the scope applications.commands (when inviting it) or else the commands won't work.
Note #2: You must install aoi.parser and setup it or else the commands won't work.
Warning: Don't try to modify the slash command maker ($createApplicationCommand) and especially not the options if you don't know what to do (since using options is extremely tough as putting even a single thing in a different position can break it.)
Code:
module.exports = [{
name: "leaderboard",
type: "interaction",
prototype: "slash",
code: `
$interactionEdit[;
{newEmbed:{title:Quiz Leaderboard!}
{description:
***Page 1***
Rank - Name - Score
$userLeaderBoard[$guildID;quizscore;asc;**{top}**) - **{username}** - **{value}**;10;1;main]}
{footer:Your rank is $getLeaderboardInfo[quizscore;$authorID;guild;top] with score $getUserVar[quizscore]}};{actionRow:{button:Next Page:1:qlb2:false:⏭️}}]
$interactionReply[Generating Quiz Leaderboard...;;;;everyone;$slashoption[hide]]
`
}, {
name: "qlb1",
type: "interaction",
prototype: "button",
code: `
$interactionUpdate[;
{newEmbed:{title:Quiz Leaderboard!}
{description:***Page 1***
Rank - Name - Score
$userLeaderBoard[$guildID;quizscore;asc;🏅**{top}**) - **{username}** - **{value}**;10;1;main]}
{footer:Your rank is $getLeaderboardInfo[quizscore;$authorID;guild;top] with score $getUserVar[quizscore]}};{actionRow:{button:Next Page:1:qlb2:false:⏭️}}]
`
}, {
name: "qlb2",
type: "interaction",
prototype: "button",
code: `
$interactionUpdate[;{newEmbed:{title:Quiz Leaderboard!}
{description:***Page 2***
Rank - Name - Score
$userLeaderBoard[$guildID;quizscore;asc;🏅**{top}**) - **{username}** - **{value}**;10;2;main]}
{footer:Your rank is $getLeaderboardInfo[quizscore;$authorID;guild;top] with score $getUserVar[quizscore]}};{actionRow:{button:Previous Page:1:qlb1:false:⏮️} {button:Next Page:1:qlb3:false:⏭️}}]
`
}, {
name: "qlb3",
type: "interaction",
prototype: "button",
code: `
$interactionUpdate[;{newEmbed:{title:Quiz Leaderboard!}
{description:***Page 3***
Rank - Name - Score
$userLeaderBoard[$guildID;quizscore;asc;🏅**{top}** - **{username}** - **{value}**;10;2;main]}
{footer:Your rank is $getLeaderboardInfo[quizscore;$authorID;guild;top] with score $getUserVar[quizscore]}};{actionRow:{button:Previous Page:1:qlb2:false:⏮️}}]
`
}]
This wiki will work on v6.5.6 best and seems to work on v6.6.1 as well, for the previous or upcoming versions, I can't give guarantee whether it will work or not.
I would really appreciate if you credit (me), when using it although it is not necessary.
When sharing it, please give credit to me.
If you have a much better API than the one I am using, please send it in this discussion (thread) I will try to make the quiz command using that.
If you think you can modify the code to make it much better or short it, a credit would be really appreciated like Original Code(s) by saiaamako
. when you post it.
If you face any problem, same message me in this discussion (thread).
EDIT: I had put a extra ` in before the correct command. I had removed it. Happy Coding.