From c2818cc00994113c70f780700b89c290ee667dc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christer=20War=C3=A9n?= Date: Mon, 18 Jul 2022 23:44:19 +0300 Subject: [PATCH] Discord.js V14 compatibility --- src/Client.ts | 4 ++-- src/client/commands/bug.js | 4 ++-- src/client/commands/invite.js | 4 ++-- src/client/commands/list.js | 4 ++-- src/client/commands/maintenance.js | 8 +++---- src/client/commands/next.js | 2 +- src/client/commands/nowplaying.js | 4 ++-- src/client/commands/play.js | 5 +++-- src/client/commands/prev.js | 2 +- src/client/commands/statistics.js | 4 ++-- src/client/commands/status.js | 16 +++++++------ src/client/commands/stop.js | 9 +++++--- src/client/events/interactionCreate.js | 8 ++++--- src/client/events/messageCreate.js | 7 +++--- src/client/events/voiceStateUpdate.js | 3 ++- src/client/funcs/check.js | 1 - src/client/funcs/listStations.js | 6 ++--- src/client/funcs/play.js | 31 ++++++++++++++------------ 18 files changed, 67 insertions(+), 55 deletions(-) diff --git a/src/Client.ts b/src/Client.ts index db0d4c8..18a83b5 100644 --- a/src/Client.ts +++ b/src/Client.ts @@ -1,4 +1,4 @@ -import Discord, { Client, Collection } from "discord.js"; +import { Client, Collection, IntentsBitField } from "discord.js"; import Datastore from "./client/classes/Datastore.js"; import Radio from "./client/classes/Radio.js"; import Stations from "./client/classes/Stations.js"; @@ -12,7 +12,7 @@ import path from "path"; const events = "./client/events/"; -const GatewayIntents = new Discord.IntentsBitField(); +const GatewayIntents = new IntentsBitField(); GatewayIntents.add( 1 << 0, // GUILDS 1 << 7, // GUILD_VOICE_STATES diff --git a/src/client/commands/bug.js b/src/client/commands/bug.js index d5081c3..87bac4a 100644 --- a/src/client/commands/bug.js +++ b/src/client/commands/bug.js @@ -1,4 +1,4 @@ -import Discord from "discord.js"; +import { EmbedBuilder } from "discord.js"; module.exports = { name: 'bug', @@ -10,7 +10,7 @@ module.exports = { message.bugTitle = client.messages.bugTitle.replace("%client.user.username%", client.user.username); message.bugDescription = client.messages.bugDescription.replace("%client.config.supportGuild%", client.config.supportGuild); - const embed = new Discord.MessageEmbed() + const embed = new EmbedBuilder() .setTitle(message.bugTitle) .setThumbnail("https://cdn.discordapp.com/emojis/" + client.messageEmojis["logo"].replace(/[^0-9]+/g, '')) .setColor(client.config.embedColor) diff --git a/src/client/commands/invite.js b/src/client/commands/invite.js index bbb20e3..d1bc453 100644 --- a/src/client/commands/invite.js +++ b/src/client/commands/invite.js @@ -1,4 +1,4 @@ -import Discord from "discord.js"; +import { EmbedBuilder } from "discord.js"; module.exports = { name: 'invite', @@ -7,7 +7,7 @@ module.exports = { execute(interaction, client) { let message = {}; message.inviteTitle = client.messages.inviteTitle.replace("%client.user.username%", client.user.username); - const embed = new Discord.MessageEmbed() + const embed = new EmbedBuilder() .setTitle(message.inviteTitle) .setColor(client.config.embedColor) .setURL("https://discord.com/api/oauth2/authorize?client_id=" + client.user.id + "&permissions=2184465408&scope=applications.commands%20bot") //View Channels, Send Messages, Embed Links, Use External Emojis, Use Slash Commands, Connect, Speak, Use Voice Activity diff --git a/src/client/commands/list.js b/src/client/commands/list.js index 6046342..50378c1 100644 --- a/src/client/commands/list.js +++ b/src/client/commands/list.js @@ -1,4 +1,4 @@ -import Discord from "discord.js"; +import { EmbedBuilder } from "discord.js"; module.exports = { name: 'list', @@ -26,7 +26,7 @@ module.exports = { stations = stations.replace('**#**', `**${i + 1}.**`); } - let embed = new Discord.MessageEmbed() + let embed = new EmbedBuilder() .setTitle(client.messages.listTitle) .setThumbnail("https://cdn.discordapp.com/emojis/" + client.messageEmojis["list"].replace(/[^0-9]+/g, '')) .setColor(client.config.embedColor) diff --git a/src/client/commands/maintenance.js b/src/client/commands/maintenance.js index e3d63a6..3c62800 100644 --- a/src/client/commands/maintenance.js +++ b/src/client/commands/maintenance.js @@ -1,4 +1,4 @@ -import Discord from "discord.js"; +import { ActionRowBuilder, EmbedBuilder, SelectMenuBuilder } from "discord.js"; import Streamer from "../classes/Streamer.js"; const _importDynamic = new Function('modulePath', 'return import(modulePath)'); const fetch = (...args) => _importDynamic('node-fetch').then(({default: fetch}) => fetch(...args)); @@ -72,9 +72,9 @@ module.exports = { } ); - const menu = new Discord.MessageActionRow() + const menu = new ActionRowBuilder() .addComponents( - new Discord.MessageSelectMenu() + new SelectMenuBuilder() .setCustomId('maintenance') .setPlaceholder('Select action') .addOptions(options) @@ -90,7 +90,7 @@ module.exports = { client.funcs.logger('Maintenance', options.find(option => option.value == action).label); - const embed = new Discord.MessageEmbed() + const embed = new EmbedBuilder() .setTitle(client.messages.maintenanceTitle) .setColor(client.config.embedColor) .setDescription(options.find(option => option.value == action).label) diff --git a/src/client/commands/next.js b/src/client/commands/next.js index 0712d74..268752a 100644 --- a/src/client/commands/next.js +++ b/src/client/commands/next.js @@ -23,7 +23,7 @@ module.exports = { radio.textChannel = interaction.channel; radio.startTime = date.getTime(); - if(interaction.isCommand()) { + if(interaction.isChatInputCommand()) { client.funcs.play(client, interaction, interaction.guild, station); } if(interaction.isButton()) { diff --git a/src/client/commands/nowplaying.js b/src/client/commands/nowplaying.js index de234a3..3b7b830 100644 --- a/src/client/commands/nowplaying.js +++ b/src/client/commands/nowplaying.js @@ -1,4 +1,4 @@ -import Discord from "discord.js"; +import { EmbedBuilder } from "discord.js"; module.exports = { name: 'nowplaying', @@ -18,7 +18,7 @@ module.exports = { message.nowplayingDescription = message.nowplayingDescription.replace("%radio.station.owner%" + "\n", radio.station.name != radio.station.owner ? radio.station.owner + "\n" : ""); message.nowplayingDescription = message.nowplayingDescription.replace("%client.funcs.msToTime(completed)%", client.funcs.msToTime(completed)); - const embed = new Discord.MessageEmbed() + const embed = new EmbedBuilder() .setTitle(client.messages.nowplayingTitle) .setThumbnail((radio.station.logo || "https://cdn.discordapp.com/emojis/" + client.messageEmojis["play"].replace(/[^0-9]+/g, ''))) .setColor(client.config.embedColor) diff --git a/src/client/commands/play.js b/src/client/commands/play.js index 0cc7df8..b1e816b 100644 --- a/src/client/commands/play.js +++ b/src/client/commands/play.js @@ -1,3 +1,4 @@ +import { PermissionFlagsBits } from "discord.js"; const { getVoiceConnection, joinVoiceChannel @@ -51,13 +52,13 @@ module.exports = { ephemeral: true }); const permissions = voiceChannel.permissionsFor(interaction.client.user); - if (!permissions.has("CONNECT")) { + if (!permissions.has(PermissionFlagsBits.Connect)) { return interaction.reply({ content: client.messageEmojis["error"] + client.messages.noPermsConnect, ephemeral: true }); } - if (!permissions.has("SPEAK")) { + if (!permissions.has(PermissionFlagsBits.Speak)) { return interaction.reply({ content: client.messageEmojis["error"] + client.messages.noPermsSpeak, ephemeral: true diff --git a/src/client/commands/prev.js b/src/client/commands/prev.js index 75a79d0..d73093f 100644 --- a/src/client/commands/prev.js +++ b/src/client/commands/prev.js @@ -23,7 +23,7 @@ module.exports = { radio.textChannel = interaction.channel; radio.startTime = date.getTime(); - if(interaction.isCommand()) { + if(interaction.isChatInputCommand()) { client.funcs.play(client, interaction, interaction.guild, station); } if(interaction.isButton()) { diff --git a/src/client/commands/statistics.js b/src/client/commands/statistics.js index 9f1073b..00d3876 100644 --- a/src/client/commands/statistics.js +++ b/src/client/commands/statistics.js @@ -1,4 +1,4 @@ -import Discord from "discord.js"; +import { EmbedBuilder } from "discord.js"; module.exports = { @@ -26,7 +26,7 @@ module.exports = { statistics = "[Open Dashboard](https://eximiabots.waren.io/radiox/" + interaction.guild.id + "/stats?info=" + Buffer.from(JSON.stringify(currentGuild), 'utf8').toString('base64') + "&globalInfo=" + Buffer.from(JSON.stringify(global), 'utf8').toString('base64') + ")" + "\n"; } - const embed = new Discord.MessageEmbed() + const embed = new EmbedBuilder() .setTitle(client.messages.statisticsTitle) .setThumbnail("https://cdn.discordapp.com/emojis/" + client.messageEmojis["statistics"].replace(/[^0-9]+/g, '')) .setColor(client.config.embedColor) diff --git a/src/client/commands/status.js b/src/client/commands/status.js index 19866c9..fa25bdd 100644 --- a/src/client/commands/status.js +++ b/src/client/commands/status.js @@ -1,4 +1,4 @@ -import Discord from "discord.js"; +import { EmbedBuilder } from "discord.js"; module.exports = { name: 'status', @@ -10,15 +10,17 @@ module.exports = { message.statusTitle = client.messages.statusTitle.replace("%client.user.username%", client.user.username); let uptime = client.funcs.msToTime(client.uptime); - const embed = new Discord.MessageEmbed() + const embed = new EmbedBuilder() .setTitle(message.statusTitle) .setThumbnail("https://cdn.discordapp.com/emojis/" + client.messageEmojis["logo"].replace(/[^0-9]+/g, '')) .setColor(client.config.embedColor) - .addField(client.messages.statusField1, uptime, false) - .addField(client.messages.statusField2, client.config.version, false) - .addField(client.messages.statusField3, Date.now() - interaction.createdTimestamp + "ms", false) - .addField(client.messages.statusField4, client.ws.ping + "ms", false) - .addField(client.messages.statusField5, client.config.hostedBy, false) + .addFields( + { name: client.messages.statusField1, value: uptime }, + { name: client.messages.statusField2, value: client.config.version }, + { name: client.messages.statusField3, value: Date.now() - interaction.createdTimestamp + "ms" }, + { name: client.messages.statusField4, value: client.ws.ping }, + { name: client.messages.statusField5, value: client.config.hostedBy }, + ) .setImage('https://waren.io/berriabot-temp-sa7a36a9xm6837br/images/empty-3.png') .setFooter({ text: client.messages.footerText, diff --git a/src/client/commands/stop.js b/src/client/commands/stop.js index 478b36c..83516f0 100644 --- a/src/client/commands/stop.js +++ b/src/client/commands/stop.js @@ -1,4 +1,4 @@ -import Discord from "discord.js"; +import { EmbedBuilder } from "discord.js"; module.exports = { name: 'stop', @@ -11,11 +11,14 @@ module.exports = { radio.connection?.destroy(); client.funcs.logger('Radio', interaction.guild.id + " / " + 'Stop'); - const embed = new Discord.MessageEmbed() + const embed = new EmbedBuilder() .setTitle(client.user.username) .setThumbnail("https://cdn.discordapp.com/emojis/" + client.messageEmojis["stop"].replace(/[^0-9]+/g, '')) .setColor(client.config.embedColor) - .addField(client.messages.nowplayingTitle, "-", true) + .addFields({ + name: client.messages.nowplayingTitle, + value: "-" + }) .setImage('https://waren.io/berriabot-temp-sa7a36a9xm6837br/images/empty-3.png') .setFooter({ text: client.messages.footerText, diff --git a/src/client/events/interactionCreate.js b/src/client/events/interactionCreate.js index c546259..320e974 100644 --- a/src/client/events/interactionCreate.js +++ b/src/client/events/interactionCreate.js @@ -1,16 +1,18 @@ +import { PermissionFlagsBits } from "discord.js"; + module.exports = { name: 'interactionCreate', async execute(client, interaction) { const permissions = interaction.channel.permissionsFor(interaction.client.user); - if (!permissions.has('VIEW_CHANNEL')) return; + if (!permissions.has(PermissionFlagsBits.ViewChannel)) return; - if (!permissions.has('EMBED_LINKS')) return interaction.reply({ + if (!permissions.has(PermissionFlagsBits.EmbedLinks)) return interaction.reply({ content: client.messageEmojis["error"] + client.messages.noPermsEmbed, ephemeral: true }); - if(interaction.isCommand()){ + if(interaction.isChatInputCommand()){ const commandName = interaction.commandName; const command = client.commands.get(commandName); if (!command) return; diff --git a/src/client/events/messageCreate.js b/src/client/events/messageCreate.js index 5ac7a48..54459e4 100644 --- a/src/client/events/messageCreate.js +++ b/src/client/events/messageCreate.js @@ -1,4 +1,5 @@ -import Discord from "discord.js"; +import { EmbedBuilder, PermissionFlagsBits } from "discord.js"; + module.exports = { name: 'messageCreate', async execute(client, message) { @@ -25,13 +26,13 @@ module.exports = { const command = client.commands.get(commandName) || client.commands.find(cmd => cmd.aliases && cmd.aliases.includes(commandName)); if (!command && message.content !== `${prefix}`) return; const permissions = message.channel.permissionsFor(message.client.user); - if (!permissions.has('EMBED_LINKS')) return message.channel.send(client.messages.noPermsEmbed); + if (!permissions.has(PermissionFlagsBits.EmbedLinks)) return message.channel.send(client.messages.noPermsEmbed); try { let newMessage = {}; newMessage.messageCommandsDeprecatedTitle = client.messages.messageCommandsDeprecatedTitle.replace("%client.user.username%", client.user.username); - const embed = new Discord.MessageEmbed() + const embed = new EmbedBuilder() .setTitle(newMessage.messageCommandsDeprecatedTitle) .setThumbnail("https://cdn.discordapp.com/emojis/" + client.messageEmojis["logo"].replace(/[^0-9]+/g, '')) .setColor(client.config.embedColor) diff --git a/src/client/events/voiceStateUpdate.js b/src/client/events/voiceStateUpdate.js index 5ea4082..09d7dc4 100644 --- a/src/client/events/voiceStateUpdate.js +++ b/src/client/events/voiceStateUpdate.js @@ -1,3 +1,4 @@ +import { PermissionFlagsBits } from "discord.js"; const { getVoiceConnection, joinVoiceChannel @@ -22,7 +23,7 @@ module.exports = { } const newPermissions = newState.channel.permissionsFor(newState.client.user); - if (!newPermissions.has("CONNECT") || !newPermissions.has("SPEAK") || !newPermissions.has("VIEW_CHANNEL")) { + if (!newPermissions.has(PermissionFlagsBits.Connect) || !newPermissions.has(PermissionFlagsBits.Speak) || !newPermissions.has(PermissionFlagsBits.ViewChannel)) { try { setTimeout( async () => ( diff --git a/src/client/funcs/check.js b/src/client/funcs/check.js index 4a5a216..8a7c153 100644 --- a/src/client/funcs/check.js +++ b/src/client/funcs/check.js @@ -1,7 +1,6 @@ module.exports = function check(client, interaction, command) { let message = {}; const radio = client.radio.get(interaction.guild.id); - const permissions = interaction.channel.permissionsFor(interaction.user); if(client.config.maintenanceMode){ interaction.reply({ content: client.messageEmojis["error"] + client.messages.maintenance, diff --git a/src/client/funcs/listStations.js b/src/client/funcs/listStations.js index 2dd73db..5921b9e 100644 --- a/src/client/funcs/listStations.js +++ b/src/client/funcs/listStations.js @@ -1,4 +1,4 @@ -import Discord from "discord.js"; +import { ActionRowBuilder, SelectMenuBuilder } from "discord.js"; module.exports = function listStations(client, interaction){ let stations = new Array(); @@ -14,9 +14,9 @@ module.exports = function listStations(client, interaction){ options.push(station); }); - const menu = new Discord.MessageActionRow() + const menu = new ActionRowBuilder() .addComponents( - new Discord.MessageSelectMenu() + new SelectMenuBuilder() .setCustomId('play') .setPlaceholder('Nothing selected') .addOptions(options) diff --git a/src/client/funcs/play.js b/src/client/funcs/play.js index b6763ab..83fc28a 100644 --- a/src/client/funcs/play.js +++ b/src/client/funcs/play.js @@ -1,4 +1,4 @@ -import Discord from "discord.js"; +import { ActionRowBuilder, ButtonBuilder, ButtonStyle, EmbedBuilder } from "discord.js"; module.exports = async function play(client, interaction, guild, station) { let message = {}; @@ -13,47 +13,50 @@ module.exports = async function play(client, interaction, guild, station) { message.nowplayingDescription = message.nowplayingDescription.replace("**", ""); message.nowplayingDescription = message.nowplayingDescription.replace("**", ""); - const embed = new Discord.MessageEmbed() + const embed = new EmbedBuilder() .setTitle(client.user.username) .setThumbnail((radio.station.logo || "https://cdn.discordapp.com/emojis/" + client.messageEmojis["play"].replace(/[^0-9]+/g, ''))) .setColor(client.config.embedColor) - .addField(client.messages.nowplayingTitle, message.nowplayingDescription, true) + .addFields({ + name: client.messages.nowplayingTitle, + value: message.nowplayingDescription + }) .setImage('https://waren.io/berriabot-temp-sa7a36a9xm6837br/images/empty-3.png') .setFooter({ text: client.messages.footerText, iconURL: "https://cdn.discordapp.com/emojis/" + client.messageEmojis["eximiabots"].replace(/[^0-9]+/g, '') }); - const buttons = new Discord.MessageActionRow() + const buttons = new ActionRowBuilder() .addComponents( - new Discord.MessageButton() + new ButtonBuilder() .setCustomId('list') .setEmoji(client.messageEmojis["list"]) - .setStyle('SECONDARY') + .setStyle(ButtonStyle.Secondary) ) .addComponents( - new Discord.MessageButton() + new ButtonBuilder() .setCustomId('prev') .setEmoji(client.messageEmojis["prev"]) - .setStyle('SECONDARY') + .setStyle(ButtonStyle.Secondary) ) .addComponents( - new Discord.MessageButton() + new ButtonBuilder() .setCustomId('stop') .setEmoji(client.messageEmojis["stop"]) - .setStyle('SECONDARY') + .setStyle(ButtonStyle.Secondary) ) .addComponents( - new Discord.MessageButton() + new ButtonBuilder() .setCustomId('next') .setEmoji(client.messageEmojis["next"]) - .setStyle('SECONDARY') + .setStyle(ButtonStyle.Secondary) ) .addComponents( - new Discord.MessageButton() + new ButtonBuilder() .setCustomId('statistics') .setEmoji(client.messageEmojis["statistics"]) - .setStyle('SECONDARY') + .setStyle(ButtonStyle.Secondary) ); if(!radio.message){