Skip to content

Commit

Permalink
Discord.js 14 upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
GreepTheSheep committed Dec 11, 2023
1 parent 6b21ab5 commit 5e93ecc
Show file tree
Hide file tree
Showing 20 changed files with 140 additions and 139 deletions.
5 changes: 3 additions & 2 deletions src/bot.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
require('dotenv').config();
const Command = require('./structures/Command'),
{ Client, Intents } = require('discord.js'),
{ Client, GatewayIntentBits, Partials } = require('discord.js'),
client = new Client({
intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES]
intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages],
partials: [Partials.Channel]
}),
TrackmaniaIO = require('trackmania.io'),
tmio = new TrackmaniaIO.Client();
Expand Down
32 changes: 16 additions & 16 deletions src/commands/campaign/campaign.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const Command = require('../../structures/Command'),
{ButtonInteraction, MessageEmbed, MessageActionRow, MessageButton, CommandInteraction, SelectMenuInteraction, Message, MessageAttachment, MessageSelectMenu} = require('discord.js'),
{ButtonInteraction, EmbedBuilder, ActionRowBuilder, ButtonBuilder, CommandInteraction, SelectMenuInteraction, Message, MessageAttachment, StringSelectMenuBuilder, ButtonStyle} = require('discord.js'),
MySQL = require('mysql'),
Table = require('easy-table');

Expand Down Expand Up @@ -113,30 +113,30 @@ exports.executeButton = async (interaction, buttonId, argument, tmio, commands,
}

const interactionComponentRows = [];
interactionComponentRows.push(new MessageActionRow());
interactionComponentRows.push(new ActionRowBuilder());

interactionComponentRows[0].addComponents(
new MessageButton()
new ButtonBuilder()
.setCustomId(this.name+'_leaderboard-up_'+clubId+'-'+campaignId)
.setLabel('⬆')
.setStyle('PRIMARY')
.setStyle(ButtonStyle.Primary)
.setDisabled(leaderboardPosFromCampaignID[campaignId] == 0)
);

interactionComponentRows[0].addComponents(
new MessageButton()
new ButtonBuilder()
.setCustomId(this.name+'_leaderboard-down_'+clubId+'-'+campaignId)
.setLabel('⬇')
.setStyle('PRIMARY')
.setStyle(ButtonStyle.Primary)
.setDisabled(leaderboardPosFromCampaignID[campaignId] + rows >= campaign.leaderboard.length)
);

if (leaderboardPosFromCampaignID[campaignId] + rows >= campaign.leaderboard.length) {
interactionComponentRows[0].addComponents(
new MessageButton()
new ButtonBuilder()
.setURL('https://trackmania.io/#/campaigns/'+clubId+'/'+campaignId)
.setLabel('View on Trackmania.io')
.setStyle('LINK')
.setStyle(ButtonStyle.Link)
);
}

Expand Down Expand Up @@ -173,11 +173,11 @@ exports.executeSelectMenu = async (interaction, categoryId, argument, tmio, comm
* Render the embeds
* @param {import('trackmania.io/typings/structures/Campaign')} campaign
* @param {import('trackmania.io').Client} tmio
* @returns {Promise<Object<MessageEmbed, MessageActionRow>>}
* @returns {Promise<Object<EmbedBuilder, ActionRowBuilder>>}
*/
async function renderCampaignEmbed(campaign, tmio){

let embed = new MessageEmbed(),
let embed = new EmbedBuilder(),
clubID = 0;

if (!campaign.isOfficial) {
Expand Down Expand Up @@ -207,20 +207,20 @@ async function renderCampaignEmbed(campaign, tmio){

const interactionComponentRows = [];
for (let i = 0; i < 2; i++) {
interactionComponentRows.push(new MessageActionRow());
interactionComponentRows.push(new ActionRowBuilder());
}

interactionComponentRows[0].addComponents(
new MessageButton()
new ButtonBuilder()
.setCustomId('campaign_leaderboard_'+clubID+'-'+campaign.id)
.setLabel('Campaign leaderboard')
.setStyle('PRIMARY')
.setStyle(ButtonStyle.Primary)
);
interactionComponentRows[0].addComponents(
new MessageButton()
new ButtonBuilder()
.setURL(`https://trackmania.io/#/campaigns/${clubID}/${campaign.id}`)
.setLabel('View on Trackmania.io')
.setStyle('LINK')
.setStyle(ButtonStyle.Link)
);

const selectOptions = [];
Expand All @@ -233,7 +233,7 @@ async function renderCampaignEmbed(campaign, tmio){
}

interactionComponentRows[1].addComponents(
new MessageSelectMenu()
new StringSelectMenuBuilder()
.setCustomId('campaign_selectMap')
.setPlaceholder('Select a map')
.addOptions(selectOptions)
Expand Down
2 changes: 1 addition & 1 deletion src/commands/campaign/currentOfficialCampaign.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const Command = require('../../structures/Command'),
{ButtonInteraction, MessageEmbed, MessageActionRow, MessageButton, CommandInteraction, SelectMenuInteraction, Message, MessageAttachment} = require('discord.js'),
{ButtonInteraction, EmbedBuilder, ActionRowBuilder, ButtonBuilder, CommandInteraction, SelectMenuInteraction, Message, MessageAttachment} = require('discord.js'),
MySQL = require('mysql'),
Table = require('easy-table'),
campaignCmd = require('./campaign');
Expand Down
14 changes: 7 additions & 7 deletions src/commands/command.js.example
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const Command = require('../../structures/Command'),
{MessageEmbed, CommandInteraction, SelectMenuInteraction, Message, MessageActionRow, MessageButton, MessageSelectMenu} = require('discord.js'),
{EmbedBuilder, CommandInteraction, SelectMenuInteraction, Message, ActionRowBuilder, ButtonBuilder, StringSelectMenuBuilder, ButtonStyle} = require('discord.js'),
MySQL = require('mysql');

/**
Expand Down Expand Up @@ -53,26 +53,26 @@ exports.execute = async (interaction, tmio, commands, sql) => {
// create 2 interaction rows (button or select menus)
const interactionComponentRows = [];
for (let i = 0; i < 2; i++) {
interactionComponentRows.push(new MessageActionRow());
interactionComponentRows.push(new ActionRowBuilder());
}

// Add 2 button to the message in the first row
interactionComponentRows[0].addComponents(
new MessageButton()
new ButtonBuilder()
.setCustomId(this.name+'_'+'button-primary')
.setLabel('Primary')
.setStyle('PRIMARY')
.setStyle(ButtonStyle.Primary)
);
interactionComponentRows[0].addComponents(
new MessageButton()
new ButtonBuilder()
.setURL('https://tmio.greep.gq')
.setLabel('TMIO')
.setStyle('LINK')
.setStyle(ButtonStyle.Link)
);

// adds a select menu to the message in the second row
interactionComponentRows[1].addComponents(
new MessageSelectMenu()
new StringSelectMenuBuilder()
.setCustomId(this.name+'_'+'select-category')
.setPlaceholder('Select here')
.addOptions([
Expand Down
18 changes: 9 additions & 9 deletions src/commands/maniapub/maniapub.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const Command = require('../../structures/Command'),
{MessageEmbed, CommandInteraction, SelectMenuInteraction, Message, ButtonInteraction, MessageActionRow, MessageButton, MessageSelectMenu} = require('discord.js'),
{EmbedBuilder, CommandInteraction, SelectMenuInteraction, Message, ButtonInteraction, ActionRowBuilder, ButtonBuilder, StringSelectMenuBuilder, ButtonStyle} = require('discord.js'),
MySQL = require('mysql');
let ads = [],
adIndex = 0;
Expand Down Expand Up @@ -43,7 +43,7 @@ exports.execute = async (interaction, tmio, commands, sql) => {

let ad = ads[adIndex];

let embed = new MessageEmbed()
let embed = new EmbedBuilder()
.setTitle(ad.name)
.setDescription(ad.url)
.setImage(ad.image)
Expand All @@ -53,21 +53,21 @@ exports.execute = async (interaction, tmio, commands, sql) => {
// create 2 interaction rows (button or select menus)
const interactionComponentRows = [];
for (let i = 0; i < 1; i++) {
interactionComponentRows.push(new MessageActionRow());
interactionComponentRows.push(new ActionRowBuilder());
}

// Add 2 button to the message in the first row
interactionComponentRows[0].addComponents(
new MessageButton()
new ButtonBuilder()
.setCustomId(this.name+'_'+'button-prev')
.setLabel('⬅')
.setStyle('PRIMARY')
.setStyle(ButtonStyle.Primary)
);
interactionComponentRows[0].addComponents(
new MessageButton()
new ButtonBuilder()
.setCustomId(this.name+'_'+'button-next')
.setLabel('➡')
.setStyle('PRIMARY')
.setStyle(ButtonStyle.Primary)
);

interaction.editReply({
Expand All @@ -90,7 +90,7 @@ exports.executeButton = async (interaction, buttonId, argument, tmio, commands,
adIndex++;
if (adIndex >= ads.length) adIndex = 0;
let ad = ads[adIndex];
let embed = new MessageEmbed()
let embed = new EmbedBuilder()
.setTitle(ad.name)
.setDescription(ad.url)
.setImage(ad.image)
Expand All @@ -104,7 +104,7 @@ exports.executeButton = async (interaction, buttonId, argument, tmio, commands,
adIndex--;
if (adIndex < 0) adIndex = ads.length-1;
let ad = ads[adIndex];
let embed = new MessageEmbed()
let embed = new EmbedBuilder()
.setTitle(ad.name)
.setDescription(ad.url)
.setImage(ad.image)
Expand Down
40 changes: 20 additions & 20 deletions src/commands/map/mapInfo.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const Command = require('../../structures/Command'),
{MessageEmbed, MessageActionRow, MessageButton, CommandInteraction, SelectMenuInteraction, ButtonInteraction, Message, MessageAttachment} = require('discord.js'),
{EmbedBuilder, ActionRowBuilder, ButtonBuilder, CommandInteraction, SelectMenuInteraction, ButtonInteraction, Message, MessageAttachment, ButtonStyle, Colors} = require('discord.js'),
MySQL = require('mysql'),
{ Time } = require('tm-essentials'),
Table = require('easy-table');
Expand Down Expand Up @@ -108,30 +108,30 @@ exports.executeButton = async (interaction, buttonId, argument, tmio, commands,
}

const interactionComponentRows = [];
interactionComponentRows.push(new MessageActionRow());
interactionComponentRows.push(new ActionRowBuilder());

interactionComponentRows[0].addComponents(
new MessageButton()
new ButtonBuilder()
.setCustomId(this.name+'_map-leaderboard-up_'+map.uid)
.setLabel('⬆')
.setStyle('PRIMARY')
.setStyle(ButtonStyle.Primary)
.setDisabled(leaderboardPosFromMapUID[argument] == 0)
);

interactionComponentRows[0].addComponents(
new MessageButton()
new ButtonBuilder()
.setCustomId(this.name+'_map-leaderboard-down_'+map.uid)
.setLabel('⬇')
.setStyle('PRIMARY')
.setStyle(ButtonStyle.Primary)
.setDisabled(leaderboardPosFromMapUID[argument] + rows >= map.leaderboard.length)
);

if (leaderboardPosFromMapUID[argument] + rows >= map.leaderboard.length) {
interactionComponentRows[0].addComponents(
new MessageButton()
new ButtonBuilder()
.setURL('https://trackmania.io/#/leaderboard/'+map.uid)
.setLabel('View on Trackmania.io')
.setStyle('LINK')
.setStyle(ButtonStyle.Link)
);
}

Expand Down Expand Up @@ -165,15 +165,15 @@ exports.executeSelectMenu = async (interaction, categoryId, argument, tmio, comm
* @param {?Number} month The Month of the TOTD
* @param {?Number} day The day of the TOTD
* @param {?Number} year The year of the TOTD
* @returns {Promise<Object<MessageEmbed, MessageActionRow>>}
* @returns {Promise<Object<EmbedBuilder, ActionRowBuilder>>}
*/
async function renderMapEmbed(tmio, uid){
return new Promise((resolve, reject) => {
let embed = new MessageEmbed();
let embed = new EmbedBuilder();

try {
tmio.maps.get(uid).then(async map => {
embed.setColor('GREEN')
embed.setColor(Colors.Green)
.setTitle(tmio.stripFormat(map.name))
.addFields([
{name:'Created by:', value:map.authorName, inline:true},
Expand All @@ -188,33 +188,33 @@ async function renderMapEmbed(tmio, uid){

// create 2 interaction rows (button or select menus)
const interactionComponentRows = [];
interactionComponentRows.push(new MessageActionRow());
interactionComponentRows.push(new ActionRowBuilder());

interactionComponentRows[0].addComponents(
new MessageButton()
new ButtonBuilder()
.setCustomId('map_map-leaderboard_'+map.uid)
.setLabel('Leaderboard')
.setStyle('PRIMARY')
.setStyle(ButtonStyle.Primary)
);

interactionComponentRows[0].addComponents(
new MessageButton()
new ButtonBuilder()
.setURL(map.url)
.setLabel('Download Map')
.setStyle('LINK')
.setStyle(ButtonStyle.Link)
);
interactionComponentRows[0].addComponents(
new MessageButton()
new ButtonBuilder()
.setURL(`https://trackmania.io/#/leaderboard/${map.uid}`)
.setLabel('Trackmania.io')
.setStyle('LINK')
.setStyle(ButtonStyle.Link)
);
if (map.exchangeId) {
interactionComponentRows[0].addComponents(
new MessageButton()
new ButtonBuilder()
.setURL(`https://trackmania.exchange/tracks/view/${map.exchangeId}`)
.setLabel('Trackmania.exchange')
.setStyle('LINK')
.setStyle(ButtonStyle.Link)
);
}

Expand Down
2 changes: 1 addition & 1 deletion src/commands/owner/eval.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const Command = require('../../structures/Command'),
{MessageEmbed, CommandInteraction, SelectMenuInteraction, Message, MessageActionRow, MessageButton, MessageSelectMenu, MessageAttachment} = require('discord.js'),
{EmbedBuilder, CommandInteraction, SelectMenuInteraction, Message, ActionRowBuilder, ButtonBuilder, StringSelectMenuBuilder, MessageAttachment} = require('discord.js'),
MySQL = require('mysql'),
fs = require('fs');

Expand Down
2 changes: 1 addition & 1 deletion src/commands/owner/forceTOTDsend.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const Command = require('../../structures/Command'),
{MessageEmbed, CommandInteraction, SelectMenuInteraction, Message, MessageActionRow, MessageButton, MessageSelectMenu} = require('discord.js'),
{EmbedBuilder, CommandInteraction, SelectMenuInteraction, Message, ActionRowBuilder, ButtonBuilder, StringSelectMenuBuilder} = require('discord.js'),
MySQL = require('mysql');

/**
Expand Down
2 changes: 1 addition & 1 deletion src/commands/owner/shell.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const Command = require('../../structures/Command'),
{MessageEmbed, CommandInteraction, SelectMenuInteraction, Message, MessageActionRow, MessageButton, MessageSelectMenu, MessageAttachment} = require('discord.js'),
{EmbedBuilder, CommandInteraction, SelectMenuInteraction, Message, ActionRowBuilder, ButtonBuilder, StringSelectMenuBuilder, MessageAttachment} = require('discord.js'),
MySQL = require('mysql'),
{ exec } = require('child_process'),
fs = require('fs');
Expand Down
Loading

0 comments on commit 5e93ecc

Please sign in to comment.