Skip to content

Commit

Permalink
🔖 [UPGRADE] | Discord.JS v14 (#18) & Various Bug Fixes
Browse files Browse the repository at this point in the history
* 🛠️ | Update Packages

* ✨ | Chat Games Updated

* ✨ | Legacy Commands Updated

* ✨ | All Events Updated

* ✨ | All Functions Updated

* ✨ | All Interactions Updated

* ✨ | All Utilities & Extras Updated

* 🐛 | Deconstruct Logger Bug Fix

* 🐛 | Intents Bug

* ✨ | Loading all guild members onReady & leaderboard now uses mentions instead of user tag.

* 🐛 | Fixed Search Bug
  • Loading branch information
NamVr authored Jul 26, 2023
1 parent 0dc7c9b commit 5ee976a
Show file tree
Hide file tree
Showing 62 changed files with 1,076 additions and 830 deletions.
9 changes: 4 additions & 5 deletions bot.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
/**
* @file Main File of the bot, responsible for registering events, commands, interactions etc.
* @author Naman Vrati
* @since 1.0.0
* @version 3.0.0
*/

// Declare constants which will be used throughout the bot.

const fs = require('fs');

const { Client, Collection, Intents } = require('discord.js');
const { REST } = require('@discordjs/rest');
const { Routes } = require('discord-api-types/v9');
const { Client, Collection, REST, Routes } = require('discord.js');

/**
* @type {import('./typings').ConfigurationFile} Config File.
Expand All @@ -25,7 +24,7 @@ const { version } = require('./package.json');
const fileExists = require('./functions/fileExists');
// Initialize LeeksLazyLogger

const Logger = require('leekslazylogger');
const { Logger } = require('leekslazylogger');
// @ts-ignore
const log = new Logger({ keepSilent: true });

Expand All @@ -37,7 +36,7 @@ const log = new Logger({ keepSilent: true });
// @ts-ignore
const client = new Client({
// Please add all intents you need, more detailed information @ https://ziad87.net/intents/
intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES],
intents: 45571,
});

/**********************************************************************/
Expand Down
10 changes: 5 additions & 5 deletions chat-triggers/math-equation.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @file Math Equation Event
* @author Naman Vrati
* @since 1.0.0
* @version 2.0.0
* @version 3.0.0
*/

const Discord = require('discord.js');
Expand Down Expand Up @@ -34,8 +34,8 @@ module.exports = {

// Send your question to the chat.

const embed = new Discord.MessageEmbed()
.setColor(`RANDOM`)
const embed = new Discord.EmbedBuilder()
.setColor(`Random`)
.setTitle(this.name + '!')
.setDescription(
`What is ${num1} ${choice == 1 ? '+' : '-'} ${num2}?`,
Expand Down Expand Up @@ -71,7 +71,7 @@ module.exports = {
msg.edit({
embeds: [
embed.setDescription(
`${embed.description}\n\n> **Nobody answered in time!** The answer was \`${answer}\`!`,
`${embed.data.description}\n\n> **Nobody answered in time!** The answer was \`${answer}\`!`,
),
],
});
Expand All @@ -84,7 +84,7 @@ module.exports = {
msg.edit({
embeds: [
embed.setDescription(
`${embed.description}\n\n> **${
`${embed.data.description}\n\n> **${
m.last().author
} was the first to answer!** The answer was \`${answer}\`!`,
),
Expand Down
45 changes: 30 additions & 15 deletions chat-triggers/speed-clicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @file Speed Clicker Event
* @author Naman Vrati
* @since 2.0.0
* @version 2.0.0
* @version 3.0.0
*/

const Discord = require('discord.js');
Expand All @@ -22,8 +22,8 @@ module.exports = {
async execute(message) {
// Send your question to the chat.

const embed = new Discord.MessageEmbed()
.setColor(`RANDOM`)
const embed = new Discord.EmbedBuilder()
.setColor(`Random`)
.setTitle(this.name + '!')
.setDescription(
'There’s one button below the message, the first person to react wins!',
Expand All @@ -32,14 +32,19 @@ module.exports = {
text: 'Be the first one to click the button to earn some coins for the shop!',
});

/**
* @type {Discord.ActionRowBuilder<Discord.ButtonBuilder>}
*/
const actionRow = new Discord.ActionRowBuilder();

const msg = await message.channel.send({
embeds: [embed],
components: [
new Discord.MessageActionRow().addComponents(
new Discord.MessageButton()
actionRow.addComponents(
new Discord.ButtonBuilder()
.setCustomId('event-clicker')
.setLabel('Speed Click!')
.setStyle('PRIMARY'),
.setStyle(Discord.ButtonStyle.Primary),
),
],
});
Expand All @@ -58,26 +63,31 @@ module.exports = {

msg.awaitMessageComponent({
filter,
componentType: 'BUTTON',
componentType: Discord.ComponentType.Button,
time: 30000,
})
.catch((err) => {})
.then((m) => {
// If no one clicked the button :(

if (!m) {
/**
* @type {Discord.ActionRowBuilder<Discord.ButtonBuilder>}
*/
const actionRow = new Discord.ActionRowBuilder();

msg.edit({
embeds: [
embed.setDescription(
`${embed.description}\n\n> **Nobody clicked in time!** It was really simple tho.`,
`${embed.data.description}\n\n> **Nobody clicked in time!** It was really simple tho.`,
),
],
components: [
new Discord.MessageActionRow().addComponents(
new Discord.MessageButton()
actionRow.addComponents(
new Discord.ButtonBuilder()
.setCustomId('event-clicker')
.setLabel('Speed Click!')
.setStyle('DANGER')
.setStyle(Discord.ButtonStyle.Danger)
.setDisabled(true),
),
],
Expand All @@ -88,18 +98,23 @@ module.exports = {

// Edit the embed after the event ends.

/**
* @type {Discord.ActionRowBuilder<Discord.ButtonBuilder>}
*/
const actionRow = new Discord.ActionRowBuilder();

msg.edit({
embeds: [
embed.setDescription(
`${embed.description}\n\n> **${m.user} was the first to click!** GG!`,
`${embed.data.description}\n\n> **${m.user} was the first to click!** GG!`,
),
],
components: [
new Discord.MessageActionRow().addComponents(
new Discord.MessageButton()
actionRow.addComponents(
new Discord.ButtonBuilder()
.setCustomId('event-clicker')
.setLabel('Speed Click!')
.setStyle('SUCCESS')
.setStyle(Discord.ButtonStyle.Success)
.setDisabled(true),
),
],
Expand Down
10 changes: 5 additions & 5 deletions chat-triggers/speed-typer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @file Speed Typer Event
* @author Naman Vrati
* @since 2.0.0
* @version 2.0.0
* @version 3.0.0
*/

// Read necessary modules
Expand Down Expand Up @@ -44,8 +44,8 @@ module.exports = {

// Send your question to the chat.

const embed = new Discord.MessageEmbed()
.setColor(`RANDOM`)
const embed = new Discord.EmbedBuilder()
.setColor(`Random`)
.setTitle(this.name + '!')
.setDescription(
`There's one sussy message below, the first person to type it wins!\n\n> \`${text}\``,
Expand Down Expand Up @@ -81,7 +81,7 @@ module.exports = {
msg.edit({
embeds: [
embed.setDescription(
`${embed.description}\n\n> **Nobody typed in time!** Was it that difficult?`,
`${embed.data.description}\n\n> **Nobody typed in time!** Was it that difficult?`,
),
],
});
Expand All @@ -94,7 +94,7 @@ module.exports = {
msg.edit({
embeds: [
embed.setDescription(
`${embed.description}\n\n> **${
`${embed.data.description}\n\n> **${
m.last().author
} was the first to type!** GG!`,
),
Expand Down
60 changes: 36 additions & 24 deletions chat-triggers/trivia-night.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @file Trivia Night Event
* @author Naman Vrati
* @since 2.0.4
* @version 2.0.4
* @version 3.0.0
*/

const Discord = require('discord.js');
Expand Down Expand Up @@ -48,48 +48,59 @@ module.exports = {

// Send your question to the chat.

const embed = new Discord.MessageEmbed()
.setColor(`RANDOM`)
const embed = new Discord.EmbedBuilder()
.setColor(`Random`)
.setTitle(this.name + '!')
.setDescription(`**${data.question}**`)
.addField(
'Difficultly',
data.difficulty[0].toUpperCase() + data.difficulty.slice(1),
true,
.addFields(
{
name: 'Difficultly',
value:
data.difficulty[0].toUpperCase() +
data.difficulty.slice(1),
inline: true,
},
{
name: 'Category',
value: data.category,
inline: true,
},
)
.addField('Category', data.category, true)
.setFooter({
text: 'You have 10 seconds to answer!',
});

// Create button options.

const optionsRow = new Discord.MessageActionRow();
/**
* @type {Discord.ActionRowBuilder<Discord.ButtonBuilder>}
*/
const optionsRow = new Discord.ActionRowBuilder();
const options = [];

// Add incorect options.

for (const [index, value] of data.incorrect_answers.entries()) {
options.push(
new Discord.MessageButton()
new Discord.ButtonBuilder()
.setCustomId(`trivia_incorrect_${index}`)
.setStyle('PRIMARY')
.setStyle(Discord.ButtonStyle.Primary)
.setLabel(value),
);
}

// Add the correct option.

options.push(
new Discord.MessageButton()
new Discord.ButtonBuilder()
.setCustomId(`trivia_correct_answer`)
.setStyle('PRIMARY')
.setStyle(Discord.ButtonStyle.Primary)
.setLabel(data.correct_answer),
);

/**
* Shuffled Options Array
* @type {Discord.MessageButton[]}
* @type {Discord.ButtonBuilder[]}
*/

const shuffledOptions = arrayShuffler(options);
Expand All @@ -108,7 +119,7 @@ module.exports = {
// Create a collector.

const collector = msg.createMessageComponentCollector({
componentType: 'BUTTON',
componentType: Discord.ComponentType.Button,
time: 10000,
});

Expand Down Expand Up @@ -150,20 +161,21 @@ module.exports = {
optionsRow.setComponents();

for (const [index, value] of shuffledOptions.entries()) {
if (value.customId.startsWith('trivia_incorrect')) {
// @ts-ignore
if (value.data.customId.startsWith('trivia_incorrect')) {
optionsRow.addComponents(
new Discord.MessageButton()
new Discord.ButtonBuilder()
.setCustomId(`trivia_incorrect_${index}`)
.setStyle('DANGER')
.setLabel(value.label)
.setStyle(Discord.ButtonStyle.Danger)
.setLabel(value.data.label)
.setDisabled(true),
);
} else {
optionsRow.addComponents(
new Discord.MessageButton()
new Discord.ButtonBuilder()
.setCustomId(`trivia_correct_answer`)
.setStyle('SUCCESS')
.setLabel(value.label)
.setStyle(Discord.ButtonStyle.Success)
.setLabel(value.data.label)
.setDisabled(true),
);
}
Expand All @@ -178,7 +190,7 @@ module.exports = {
msg.edit({
embeds: [
embed.setDescription(
`${embed.description}\n\n> **Nobody answered correctly in time!** The answer was \`${data.correct_answer}\`!`,
`${embed.data.description}\n\n> **Nobody answered correctly in time!** The answer was \`${data.correct_answer}\`!`,
),
],
components: [optionsRow],
Expand All @@ -192,7 +204,7 @@ module.exports = {
msg.edit({
embeds: [
embed.setDescription(
`${embed.description}\n\n> **${
`${embed.data.description}\n\n> **${
m.last().user
} was the first to answer!** The answer was \`${
data.correct_answer
Expand Down
10 changes: 5 additions & 5 deletions chat-triggers/unscramble-the-word.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @file Unscramble The Word Event
* @author Naman Vrati
* @since 2.0.0
* @version 2.0.0
* @version 3.0.0
*/

// Read necessary modules
Expand Down Expand Up @@ -47,8 +47,8 @@ module.exports = {

// Send your question to the chat.

const embed = new Discord.MessageEmbed()
.setColor(`RANDOM`)
const embed = new Discord.EmbedBuilder()
.setColor(`Random`)
.setTitle(this.name + '!')
.setDescription(
`I have scrambled a word, unscramble it to win some coins!\n\n> \`${word}\``,
Expand Down Expand Up @@ -84,7 +84,7 @@ module.exports = {
msg.edit({
embeds: [
embed.setDescription(
`${embed.description}\n\n> **Nobody answered in time!** The answer was \`${answer}\`!`,
`${embed.data.description}\n\n> **Nobody answered in time!** The answer was \`${answer}\`!`,
),
],
});
Expand All @@ -97,7 +97,7 @@ module.exports = {
msg.edit({
embeds: [
embed.setDescription(
`${embed.description}\n\n> **${
`${embed.data.description}\n\n> **${
m.last().author
} was the first to answer!** The answer was \`${answer}\`!`,
),
Expand Down
Loading

0 comments on commit 5ee976a

Please sign in to comment.