toowake

Game.js

Apr 29th, 2023
970
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.15 KB | None | 0 0
  1. const { SlashCommandBuilder, EmbedBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle } = require("discord.js");
  2. const { Hangman, wordle } = require(`discord-gamecord`);
  3. const math = require('mathjs');
  4. const wiki = require("wikijs");
  5.  
  6. module.exports = {
  7. data: new SlashCommandBuilder()
  8. .setName("games")
  9. .setDescription("Game Commands")
  10. .addSubcommand(command => command
  11. .setName("8ball")
  12. .setDescription("8ball game")
  13. .addStringOption(option => option
  14. .setName("question")
  15. .setDescription("Your Question")
  16. .setRequired(true)
  17. ))
  18. .addSubcommand(command => command
  19. .setName("random")
  20. .setDescription("random text")
  21. .addStringOption(option => option
  22. .setName("option-1")
  23. .setDescription("the first option")
  24. .setRequired(true)
  25. )
  26. .addStringOption(option => option
  27. .setName("option-2")
  28. .setDescription("The second option")
  29. .setRequired(true)
  30. ))
  31. .addSubcommand(command => command
  32. .setName("coinflip")
  33. .setDescription("headsntails")
  34. .addStringOption(option => option
  35. .setName("answer")
  36. .setDescription("head or tail")
  37. .setRequired(true)
  38. .addChoices(
  39. {name: "head", value: "head"},
  40. {name: "tail", value: "tail"}
  41. )
  42. ))
  43. .addSubcommand(command => command
  44. .setName("hangman")
  45. .setDescription("Play hangman")
  46. )
  47. .addSubcommand(command => command
  48. .setName("dice")
  49. .setDescription("random number between 1 and 6")
  50. )
  51. .addSubcommand(command => command
  52. .setName("wordle")
  53. .setDescription("play wordle")
  54. )
  55. .addSubcommand(command => command
  56. .setName("calculator")
  57. .setDescription("Calculate something")
  58. ),
  59.  
  60. async execute (interaction, client) {
  61. const sub = interaction.options.getSubcommand();
  62.  
  63. switch (sub) {
  64. case '8ball':
  65. const question = interaction.options.getString('question');
  66. const choice = ["🎱| It is certian.", "🎱| It is decidedly so.", "🎱| Without a doubt.", "🎱| Yes definitely.", "🎱| You may rely on it.", "🎱| As I see it, yes.", "🎱| Most likely.", "🎱| Outlook good.", "🎱| Yes.", "🎱| Signs point to yes.", "🎱| Reply hazy, try again.", "🎱| Ask again later.", "🎱| Better not tell you now.", "🎱| Cannot predict now.", "🎱| Concentrate and ask again.", "🎱| Don't count on it.", "🎱| My reply is no.", "🎱| My sources say no.", "🎱| Outlook not so good.", "🎱| Very doubtful."]
  67. const ball = Math.floor(Math.random() * choice.length);
  68.  
  69. const embed = new EmbedBuilder()
  70. .setColor("Blue")
  71. .setTitle(`🎱| ${interaction.user.username}'s 8ball game`)
  72. .addFields({ name: "Question", value: `${question}`, inline: true})
  73.  
  74. const embed2 = new EmbedBuilder()
  75. .setColor("Blue")
  76. .setTitle(`🎱| ${interaction.user.username}'s 8ball game`)
  77. .addFields({ name: "Question", value: `${question}`, inline: true})
  78. .addFields({ name: "Answer", value: `${choice[ball]}`, inline: true})
  79.  
  80. const button = new ActionRowBuilder()
  81. .addComponents(
  82. new ButtonBuilder()
  83. .setCustomId('button')
  84. .setLabel(`🎱 Roll the ball!`)
  85. .setStyle(ButtonStyle.Primary)
  86. )
  87.  
  88. const msg = await interaction.reply({ embeds: [embed], components: [button] });
  89.  
  90. const collector = msg.createMessageComponentCollector()
  91.  
  92. collector.on('collect', async i => {
  93. if (i.customId == 'button') {
  94. i.update({ embeds: [embed2], components: [] })
  95. }
  96. })
  97. break;
  98. case 'coinflip':
  99. await interaction.deferReply()
  100.  
  101. const answer = interaction.options.getString("answer")
  102. const choices = ["head", "tail"]
  103. const text = Math.floor(Math.random() * choices.length);
  104.  
  105. const embed1 = new EmbedBuilder()
  106. .setColor("Red")
  107. .setTitle("YOU LOST!")
  108. .addFields({name: "Your answer:", value:`πŸͺ™ ${answer}`, inline: true})
  109. .addFields({name: "My answer:", value:`πŸͺ™ ${choices[text]}`, inline: true})
  110.  
  111. const embed3 = new EmbedBuilder()
  112. .setColor("Green")
  113. .setTitle("YOU WON!")
  114. .addFields({name: "Your answer:", value:`πŸͺ™ ${answer}`, inline: true})
  115. .addFields({name: "My answer:", value:`πŸͺ™ ${choices[text]}`, inline: true})
  116.  
  117. if (answer == choices[text]) {
  118. await interaction.followUp({embeds: [embed3]})
  119. }
  120.  
  121. if (answer !== choices[text]) {
  122. await interaction.followUp({embeds: [embed1]})
  123. }
  124. break;
  125. case 'hangman':
  126. const Game = new Hangman({
  127. message: interaction,
  128. embed: {
  129. title: `Hangman`,
  130. color: `#5865F2`
  131. },
  132. hangman: { hat: "🎩", head: `πŸ‘¨β€πŸ¦°`, shirt: `πŸ‘•`, pants: `🩳`, boots: `πŸ₯ΎπŸ₯Ύ`},
  133. timeoutTime: 60000,
  134. timeWords: "all",
  135. winMessage: `You won! The word was **{word}**`,
  136. loseMessage: `You lost! The word was **{word}**`,
  137. playerOnlyMessage: `Only {player} can use these buttons`,
  138. })
  139.  
  140. Game.startGame();
  141. Game.on(`gameOver`, result => {
  142. return;
  143. });
  144. break;
  145. case 'dice':
  146.  
  147. const Nums = [ "1", "2", "3", "4", "5", "6"];
  148. const ballz = Math.floor(Math.random() * Nums.length);
  149.  
  150. const embed500 = new EmbedBuilder()
  151. .setTitle("dice")
  152. .addFields(
  153. {name: "Number:", value: `${ballz}`, inline: true},
  154. {name: "Requested by:", value: `<@${interaction.user.id}>`}
  155. )
  156. .setColor("Green")
  157.  
  158. return await interaction.reply({
  159. embeds: [embed500]
  160. });
  161. break;
  162. case 'worlde':
  163. const Gamex = new Wordle({
  164. message: interaction,
  165. isSlashGame: false,
  166. embed: {
  167. title: `Wordle`,
  168. color: '#5865F2'
  169. },
  170. customWord: null,
  171. timeoutTime: 60000,
  172. winMessage: 'You won! The word was **{word}**',
  173. loseMessage: 'You lost! The word was **{word}**',
  174. playerOnlyMessage: 'Only {player} cam ise these buttons'
  175. });
  176.  
  177. Gamex.startGame();
  178. Gamex.on('gameOver', result => {
  179. return;
  180. })
  181. break;
  182. case 'calculator':
  183. const idPrefix = 'calulator'
  184.  
  185. const embed700 = new EmbedBuilder()
  186. .setDescription("```\nResults will be displayed here\n```")
  187. .setColor('Blue')
  188.  
  189. const row = new ActionRowBuilder()
  190. .addComponents(
  191. new ButtonBuilder()
  192. .setLabel('AC')
  193. .setCustomId(idPrefix + "_clear")
  194. .setStyle(ButtonStyle.Danger),
  195. new ButtonBuilder()
  196. .setLabel('(')
  197. .setCustomId(idPrefix + "_(")
  198. .setStyle(ButtonStyle.Primary),
  199. new ButtonBuilder()
  200. .setLabel(')')
  201. .setCustomId(idPrefix + "_)")
  202. .setStyle(ButtonStyle.Primary),
  203. new ButtonBuilder()
  204. .setLabel('<=')
  205. .setCustomId(idPrefix + "_backspace")
  206. .setStyle(ButtonStyle.Primary)
  207. )
  208.  
  209. const row1 = new ActionRowBuilder()
  210. .addComponents(
  211. new ButtonBuilder()
  212. .setLabel('1')
  213. .setCustomId(idPrefix + "_1")
  214. .setStyle(ButtonStyle.Secondary),
  215. new ButtonBuilder()
  216. .setLabel('2')
  217. .setCustomId(idPrefix + "_2")
  218. .setStyle(ButtonStyle.Secondary),
  219. new ButtonBuilder()
  220. .setLabel('3')
  221. .setCustomId(idPrefix + "_3")
  222. .setStyle(ButtonStyle.Secondary),
  223. new ButtonBuilder()
  224. .setLabel('/')
  225. .setCustomId(idPrefix + "_/")
  226. .setStyle(ButtonStyle.Primary)
  227. )
  228.  
  229. const row2 = new ActionRowBuilder()
  230. .addComponents(
  231. new ButtonBuilder()
  232. .setLabel('4')
  233. .setCustomId(idPrefix + "_4")
  234. .setStyle(ButtonStyle.Secondary),
  235. new ButtonBuilder()
  236. .setLabel('5')
  237. .setCustomId(idPrefix + "_5")
  238. .setStyle(ButtonStyle.Secondary),
  239. new ButtonBuilder()
  240. .setLabel('6')
  241. .setCustomId(idPrefix + "_6")
  242. .setStyle(ButtonStyle.Secondary),
  243. new ButtonBuilder()
  244. .setLabel('*')
  245. .setCustomId(idPrefix + "_*")
  246. .setStyle(ButtonStyle.Primary)
  247. )
  248.  
  249. const row3 = new ActionRowBuilder()
  250. .addComponents(
  251. new ButtonBuilder()
  252. .setLabel('7')
  253. .setCustomId(idPrefix + "_7")
  254. .setStyle(ButtonStyle.Secondary),
  255. new ButtonBuilder()
  256. .setLabel('8')
  257. .setCustomId(idPrefix + "_8")
  258. .setStyle(ButtonStyle.Secondary),
  259. new ButtonBuilder()
  260. .setLabel('9')
  261. .setCustomId(idPrefix + "_9")
  262. .setStyle(ButtonStyle.Secondary),
  263. new ButtonBuilder()
  264. .setLabel('-')
  265. .setCustomId(idPrefix + "_-")
  266. .setStyle(ButtonStyle.Primary)
  267. )
  268.  
  269. const row4 = new ActionRowBuilder()
  270. .addComponents(
  271. new ButtonBuilder()
  272. .setLabel('0')
  273. .setCustomId(idPrefix + "_0")
  274. .setStyle(ButtonStyle.Secondary),
  275. new ButtonBuilder()
  276. .setLabel('.')
  277. .setCustomId(idPrefix + "_.")
  278. .setStyle(ButtonStyle.Secondary),
  279. new ButtonBuilder()
  280. .setLabel('=')
  281. .setCustomId(idPrefix + "_=")
  282. .setStyle(ButtonStyle.Success),
  283. new ButtonBuilder()
  284. .setLabel('+')
  285. .setCustomId(idPrefix + "_+")
  286. .setStyle(ButtonStyle.Primary)
  287. )
  288.  
  289. const msg2 = await interaction.reply({ embeds: [embed700], components: [row, row1, row2, row3, row4], ephemeral: false });
  290.  
  291. let data = "";
  292. const col = msg2.createMessageComponentCollector({
  293. filter: i => i.user.id === interaction.user.id,
  294. time: 600000
  295. });
  296.  
  297. col.on('collect', async (i) => {
  298. const id = i.customId
  299. const value = id.split('_')[1];
  300. let extra = "";
  301.  
  302. if (value === "=") {
  303. try {
  304. data = math.evaluate(data).toString();
  305. } catch (e) {
  306. data = "";
  307. extra = "An Error Occured, Please click on AC for restart";
  308. }
  309. } else if (value === "clear") {
  310. data = "";
  311. extra = "Results will be displayed here"
  312. } else if (value === "backspace") {
  313. data = data.slice(0, -1);
  314. } else {
  315. const lc = data[data.length - 1];
  316.  
  317. data += `${(
  318. (parseInt(value) == value || value === ".")
  319. &&
  320. (lc == parseInt(lc) || lc === ".")
  321. ) || data.length === 0 ? "" : " "}` + value;
  322. }
  323.  
  324. i.update({ embeds: [new EmbedBuilder().setColor('Blue').setDescription(`\`\`\`\n${data || extra}\n\`\`\``)], components: [row, row1, row2, row3, row4], ephemeral: false })
  325. })
  326. break;
  327. case 'random':
  328. const op1 = interaction.options.getString("option-1");
  329. const op2 = interaction.options.getString("option-2");
  330. const choices7 = [`${op1}`, `${op2}`];
  331.  
  332. const answer7 = Math.floor(Math.random() * choices7.length);
  333.  
  334. const embed70000 = new EmbedBuilder()
  335. .setTitle("Here is the answer!")
  336. .addFields({ name: `User: `, value: `<@${interaction.user.id}>`, inline: true})
  337. .addFields({ name: `Answer: `, value: `${choices7[answer7]}`, inline: true})
  338. .addFields({ name: "Option 1: ", value: `${op1}`, inline: false})
  339. .addFields({ name: "Option 2: ", value: `${op2}`})
  340. .setColor("Random")
  341. .setTimestamp()
  342.  
  343. return interaction.reply({ embeds: [embed70000] });
  344.  
  345.  
  346. }
  347. }
  348.  
  349. }
Advertisement
Add Comment
Please, Sign In to add comment