1+ const { EmbedBuilder } = require ( "discord.js" ) ;
2+
3+ module . exports = {
4+ name : 'sbtrivia' ,
5+ description : 'Plays a Skyblock trivia game!' ,
6+ options : [ ] ,
7+ execute : async ( interaction ) => {
8+ try {
9+ // Check if interaction is already replied or deferred
10+ if ( ! interaction . replied && ! interaction . deferred ) {
11+ await interaction . deferReply ( { ephemeral : true } ) ; // Defer reply to allow time
12+ }
13+
14+ // Notify user the game is starting
15+ await interaction . editReply ( {
16+ content : 'Starting the trivia game! Check the channel for your question.' ,
17+ } ) ;
18+
19+ // Start trivia game
20+ await playTrivia ( interaction . channel , interaction . user ) ;
21+ } catch ( error ) {
22+ console . error ( 'Error handling interaction:' , error ) ;
23+
24+ // Fallback: If the interaction hasn't been replied, send an error message
25+ if ( ! interaction . replied ) {
26+ await interaction . reply ( {
27+ content : 'An error occurred while starting the trivia game. Please try again later.' ,
28+ ephemeral : true ,
29+ } ) ;
30+ }
31+ }
32+ } ,
33+ } ;
34+
35+ async function playTrivia ( channel , user ) {
36+ const triviaQuestions = [
37+ {
38+ question : "Who is the final boss of Floor 7 in Hypixel Skyblock dungeons?" ,
39+ options : [ "1. Necron" , "2. Sadan" , "3. Maxor" , "4. Goldor" ] ,
40+ answer : 1 ,
41+ } ,
42+ {
43+ question : "Which item is crafted using Diamante's Handles?" ,
44+ options : [ "1. Hyperion" , "2. Valkyrie" , "3. Shadow Assassin Chestplate" , "4. Flower of Truth" ] ,
45+ answer : 2 ,
46+ } ,
47+ {
48+ question : "What is the reward for defeating the Livid boss?" ,
49+ options : [ "1. Adaptive Armor" , "2. Shadow Assassin Armor" , "3. Spirit Bow" , "4. Bonzo's Staff" ] ,
50+ answer : 2 ,
51+ } ,
52+ {
53+ question : "Which dungeon floor introduces the Spirit Sceptre?" ,
54+ options : [ "1. Floor 1" , "2. Floor 3" , "3. Floor 4" , "4. Floor 5" ] ,
55+ answer : 3 ,
56+ } ,
57+ {
58+ question : "What is the name of the dungeon hub NPC who gives daily quests?" ,
59+ options : [ "1. Ophelia" , "2. Mort" , "3. Malik" , "4. Elizabeth" ] ,
60+ answer : 2 ,
61+ } ,
62+ {
63+ question : "Which material is used to craft the Flower of Truth?" ,
64+ options : [ "1. Enchanted Poppy" , "2. Enchanted Dandelion" , "3. Enchanted Rose" , "4. Enchanted Bone" ] ,
65+ answer : 3 ,
66+ } ,
67+ {
68+ question : "What is the ability of the Hyperion?" ,
69+ options : [ "1. Implosion" , "2. Wither Shield" , "3. Seismic Wave" , "4. Ragnarok" ] ,
70+ answer : 1 ,
71+ } ,
72+ {
73+ question : "Which dungeon boss drops the Giant's Sword?" ,
74+ options : [ "1. Necron" , "2. Sadan" , "3. Livid" , "4. Thorn" ] ,
75+ answer : 2 ,
76+ } ,
77+ {
78+ question : "What is the maximum catacombs level in Hypixel Skyblock?" ,
79+ options : [ "1. 30" , "2. 40" , "3. 50" , "4. 60" ] ,
80+ answer : 3 ,
81+ } ,
82+ {
83+ question : "Which dungeon class specializes in healing?" ,
84+ options : [ "1. Tank" , "2. Healer" , "3. Mage" , "4. Berserk" ] ,
85+ answer : 2 ,
86+ } ,
87+ {
88+ question : "What does the Spirit Bow do?" ,
89+ options : [ "1. Shoots healing arrows" , "2. Summons mobs" , "3. Shoots through walls" , "4. Damages Thorn during the boss fight" ] ,
90+ answer : 4 ,
91+ } ,
92+ {
93+ question : "Which NPC in the dungeon hub reforges items?" ,
94+ options : [ "1. Mort" , "2. Malik" , "3. Ophelia" , "4. Elizabeth" ] ,
95+ answer : 2 ,
96+ } ,
97+ {
98+ question : "What is the cooldown of the Bonzo Staff ability?" ,
99+ options : [ "1. 0.5 seconds" , "2. 1 second" , "3. 2 seconds" , "4. 3 seconds" ] ,
100+ answer : 2 ,
101+ } ,
102+ {
103+ question : "Which class is known for ranged attacks?" ,
104+ options : [ "1. Tank" , "2. Mage" , "3. Archer" , "4. Healer" ] ,
105+ answer : 3 ,
106+ } ,
107+ {
108+ question : "What is the name of the NPC who sells dungeon gear?" ,
109+ options : [ "1. Malik" , "2. Mort" , "3. Ophelia" , "4. Elizabeth" ] ,
110+ answer : 3 ,
111+ } ,
112+ {
113+ question : "What is the cost of a Booster Cookie from the Community Shop?" ,
114+ options : [ "1. 325 Gems" , "2. 400 Gems" , "3. 500 Gems" , "4. 600 Gems" ] ,
115+ answer : 1 , // 325 Gems
116+ } ,
117+ {
118+ question : "Which NPC upgrades minion storage?" ,
119+ options : [ "1. Jerry" , "2. Kat" , "3. Elizabeth" , "4. None of the above" ] ,
120+ answer : 3 , // Elizabeth
121+ } ,
122+ {
123+ question : "What is the crafting material for a Midas' Staff?" ,
124+ options : [ "1. Gold Blocks" , "2. Enchanted Gold" , "3. Enchanted Gold Blocks" , "4. Enchanted Iron Blocks" ] ,
125+ answer : 3 , // Enchanted Gold Blocks
126+ } ,
127+ {
128+ question : "What is the default maximum island size?" ,
129+ options : [ "1. 120x120" , "2. 160x160" , "3. 240x240" , "4. 320x320" ] ,
130+ answer : 2 , // 160x160
131+ } ,
132+ {
133+ question : "What ability does the Scylla sword have?" ,
134+ options : [ "1. Implosion" , "2. Wither Shield" , "3. Seismic Wave" , "4. True Damage" ] ,
135+ answer : 2 , // Wither Shield
136+ } ,
137+ {
138+ question : "How many coins does a Slayer quest cost to start at level 3?" ,
139+ options : [ "1. 5,000" , "2. 10,000" , "3. 15,000" , "4. 20,000" ] ,
140+ answer : 2 , // 10,000
141+ } ,
142+ {
143+ question : "Which of these is not a dungeon potion effect?" ,
144+ options : [ "1. Speed" , "2. Strength" , "3. Agility" , "4. Health" ] ,
145+ answer : 3 , // Agility
146+ } ,
147+ {
148+ question : "What is the name of the Wither armor upgraded to Necron's Armor?" ,
149+ options : [ "1. Goldor's Armor" , "2. Wither Armor" , "3. Maxor's Armor" , "4. Shadow Assassin" ] ,
150+ answer : 2 , // Wither Armor
151+ } ,
152+ {
153+ question : "What pet increases combat wisdom by 30?" ,
154+ options : [ "1. Ender Dragon" , "2. Griffin" , "3. Mithril Golem" , "4. Wolf" ] ,
155+ answer : 4 , // Wolf
156+ } ,
157+ {
158+ question : "What is the name of the NPC that sells the Flower Minion?" ,
159+ options : [ "1. Rosetta" , "2. Shania" , "3. Tomioka" , "4. Anita" ] ,
160+ answer : 4 , // Anita
161+ } ,
162+ {
163+ question : "How many Fairy Souls are there in total?" ,
164+ options : [ "1. 193" , "2. 204" , "3. 211" , "4. 234" ] ,
165+ answer : 2 , // 204
166+ } ,
167+ {
168+ question : "What is the base damage of the Livid Dagger?" ,
169+ options : [ "1. 150" , "2. 160" , "3. 175" , "4. 200" ] ,
170+ answer : 1 , // 150
171+ } ,
172+ {
173+ question : "What is the ability of the Aspect of the End sword?" ,
174+ options : [ "1. Teleport" , "2. Fire Beam" , "3. Damage Over Time" , "4. Lifesteal" ] ,
175+ answer : 1 , // Teleport
176+ } ,
177+ {
178+ question : "What reforge increases critical chance the most?" ,
179+ options : [ "1. Spicy" , "2. Fabled" , "3. Sharp" , "4. Precise" ] ,
180+ answer : 3 , // Sharp
181+ } ,
182+ {
183+ question : "How much mana does the Ink Wand ability cost?" ,
184+ options : [ "1. 50" , "2. 100" , "3. 150" , "4. 200" ] ,
185+ answer : 4 , // 200
186+ } ,
187+ {
188+ question : "What is the cooldown of the Jerry-chine Gun?" ,
189+ options : [ "1. None" , "2. 1 second" , "3. 0.5 seconds" , "4. 0.2 seconds" ] ,
190+ answer : 4 , // 0.2 seconds
191+ } ,
192+ ] ;
193+
194+ // Delete any existing messages before starting
195+ let previousMessages = await channel . messages . fetch ( { limit : 5 } ) ; // Fetch last 5 messages (adjust as needed)
196+ previousMessages = previousMessages . filter ( msg => msg . author . bot ) ; // Filter out non-bot messages
197+ await Promise . all ( previousMessages . map ( msg => msg . delete ( ) ) ) ; // Delete bot messages
198+
199+ const randomQuestion = triviaQuestions [ Math . floor ( Math . random ( ) * triviaQuestions . length ) ] ;
200+
201+ const questionEmbed = new EmbedBuilder ( )
202+ . setColor ( '#0099ff' )
203+ . setTitle ( '🧠 Dungeon Trivia!' )
204+ . setDescription ( randomQuestion . question )
205+ . addFields ( randomQuestion . options . map ( ( option , index ) => ( {
206+ name : `Option ${ index + 1 } ` ,
207+ value : option ,
208+ } ) ) )
209+ . setFooter ( { text : 'Reply with the number of your answer.' } ) ;
210+
211+ // Send trivia question to the channel
212+ const questionMessage = await channel . send ( { embeds : [ questionEmbed ] } ) ;
213+
214+ const filter = ( msg ) => msg . author . id === user . id ;
215+ const collector = channel . createMessageCollector ( { filter, time : 30000 } ) ;
216+
217+ collector . on ( 'collect' , async ( msg ) => {
218+ const answer = parseInt ( msg . content , 10 ) ;
219+
220+ if ( ! isNaN ( answer ) && answer >= 1 && answer <= randomQuestion . options . length ) {
221+ collector . stop ( ) ;
222+
223+ const correctEmbed = new EmbedBuilder ( )
224+ . setColor ( answer === randomQuestion . answer ? '#00ff00' : '#ff0000' )
225+ . setTitle ( answer === randomQuestion . answer ? '🎉 Correct!' : '❌ Incorrect!' )
226+ . setDescription (
227+ answer === randomQuestion . answer
228+ ? 'Well done!'
229+ : `The correct answer was: ${ randomQuestion . options [ randomQuestion . answer - 1 ] } `
230+ ) ;
231+
232+ // Delete the trivia question message after a 3-second delay
233+ setTimeout ( ( ) => {
234+ questionMessage . delete ( ) ;
235+ } , 3000 ) ;
236+
237+ const correctMessage = await channel . send ( { embeds : [ correctEmbed ] } ) ;
238+
239+ const playAgainEmbed = new EmbedBuilder ( )
240+ . setColor ( '#0099ff' )
241+ . setTitle ( 'Play Again?' )
242+ . setDescription ( 'Reply with `yes` to play again or `no` to stop.' ) ;
243+
244+ // Send and delete the play-again message after 3 seconds
245+ const playAgainMessage = await channel . send ( { embeds : [ playAgainEmbed ] } ) ;
246+
247+ const playAgainCollector = channel . createMessageCollector ( { filter, time : 10000 } ) ; // Timeout after 10 seconds
248+
249+ playAgainCollector . on ( 'collect' , async ( response ) => {
250+ const lowerResponse = response . content . toLowerCase ( ) ;
251+
252+ if ( lowerResponse === 'yes' ) {
253+ playAgainCollector . stop ( ) ;
254+ await playTrivia ( channel , user ) ; // Recursive call for replay
255+ } else if ( lowerResponse === 'no' ) {
256+ playAgainCollector . stop ( ) ;
257+ const goodbyeEmbed = new EmbedBuilder ( )
258+ . setColor ( '#0099ff' )
259+ . setTitle ( 'Goodbye!' )
260+ . setDescription ( 'Thanks for playing!' ) ;
261+
262+ await channel . send ( { embeds : [ goodbyeEmbed ] } ) ;
263+ } else {
264+ await channel . send ( 'Please reply with either `yes` or `no`.' ) ;
265+ }
266+
267+ // Delete the play-again message after a 3-second delay
268+ setTimeout ( ( ) => {
269+ playAgainMessage . delete ( ) ;
270+ } , 3000 ) ;
271+ } ) ;
272+
273+ playAgainCollector . on ( 'end' , async ( _ , reason ) => {
274+ if ( reason === 'time' ) {
275+ const timeoutEmbed = new EmbedBuilder ( )
276+ . setColor ( '#ff0000' )
277+ . setTitle ( '⏰ Time\'s up!' )
278+ . setDescription ( 'You didn\'t reply in time.' ) ;
279+
280+ await channel . send ( { embeds : [ timeoutEmbed ] } ) ;
281+
282+ // Delete the play-again message after a 3-second delay
283+ setTimeout ( ( ) => {
284+ playAgainMessage . delete ( ) ;
285+ } , 3000 ) ;
286+ }
287+ } ) ;
288+
289+ // Delete the correct message after a 3-second delay
290+ setTimeout ( ( ) => {
291+ correctMessage . delete ( ) ;
292+ } , 3000 ) ;
293+ } else {
294+ await channel . send ( 'Please reply with a valid option number.' ) ;
295+ }
296+ } ) ;
297+
298+ collector . on ( 'end' , async ( _ , reason ) => {
299+ if ( reason === 'time' ) {
300+ const timeoutEmbed = new EmbedBuilder ( )
301+ . setColor ( '#ff0000' )
302+ . setTitle ( '⏰ Time\'s up!' )
303+ . setDescription ( 'You didn\'t reply in time.' ) ;
304+
305+ // Delete the timeout message after a 3-second delay
306+ setTimeout ( ( ) => {
307+ channel . send ( { embeds : [ timeoutEmbed ] } ) ;
308+ } , 3000 ) ;
309+ }
310+ } ) ;
311+ }
312+
313+ //CODED BY Mr_Bear_First !!
314+ //Made into a discord version by XoticTK (with help from chatgpt because im tired and did NOT feel like doin allat)
0 commit comments