Discord.js v13 code breaks when upgrading to v14

Discord.js v14 includes many breaking changes. It now requires Node 16.9 or higher to use, so make sure you upgrade to the latest LTS version.

This version of v14 uses the Discord API v10.

Errors with intents:

// v13
const client = new Client({
  intents: [
    Intents.FLAGS.GUILDS,
    Intents.FLAGS.GUILD_MESSAGES,
  ],
});

// OR
const client = new Client({
  intents: ['GUILDS', 'GUILD_MESSAGES'],
});

// v14
const { Client, GatewayIntentBits } = require('discord.js');
const client = new Client({
  intents: [
    GatewayIntentBits.Guilds,
    GatewayIntentBits.GuildMessages,
  ],
});

For a full list of GatewayIntentBits, you can read this answer.

Errors with interactions:

Some interaction type guards have been removed. You can compare interaction.type against the InteractionType enum instead.

const { InteractionType } = require('discord.js');

// v13
if (interaction.isCommand()) {}
// v14
if (interaction.type === InteractionType.ApplicationCommand) {}

// v13
if (interaction.isAutocomplete()) {}
// v14
if (interaction.type === InteractionType.ApplicationCommandAutocomplete) {}

// v13
if (interaction.isMessageComponent()) {}
// v14
if (interaction.type === InteractionType.MessageComponent) {}

// v13
if (interaction.isModalSubmit()) {}
// v14
if (interaction.type === InteractionType.ModalSubmit) {}

Errors with channels:

Some channel type guards have been removed. To narrow channels, you can compare channel.type to a ChannelType enum instead.

const { ChannelType } = require('discord.js');
// v13
if (message.channel.isText()) {}
// v14
if (channel.type === ChannelType.GuildText) {}

// v13
if (message.channel.isVoice()) {}
// v14
if (channel.type === ChannelType.GuildVoice) {}

// v13
if (message.channel.isDM()) {}
// v14
if (channel.type === ChannelType.DM) {}

// v13
if (message.channel.isCategory()) {}
// v14
if (channel.type === ChannelType.GuildCategory) {}

For a full list of ChannelTypes, you can read this answer.

Also, there are some new type guards:

channel.isDMBased();
channel.isTextBased();
channel.isVoiceBased();

Errors with builders and embeds:

MessageEmbed has been renamed to EmbedBuilder.

// v13
const embed = new MessageEmbed();
// v14
const { EmbedBuilder } = require('discord.js');
const embed = new EmbedBuilder();

MessageComponents have been renamed; they no longer have the Message prefix and now have a Builder suffix.

// v13
const button = new MessageButton();
// v14 
const { ButtonBuilder } = require('discord.js');
const button = new ButtonBuilder();

// v13
const actionRow = new MessageActionRow();
// v14 
const { ActionRowBuilder } = require('discord.js');
const actionRow = new ActionRowBuilder();

// v13
const selectMenu = new MessageSelectMenu();
// v14
const { SelectMenuBuilder } = require('discord.js');
const selectMenu = new SelectMenuBuilder();

// v13
const textInput = new TextInputComponent();
// v14
const { TextInputBuilder } = require('discord.js');
const textInput = new TextInputBuilder();

Errors with enums:

Any areas that used to accept a string or number type for an enum parameter will now only accept exclusively numbers.

// Wrong
new ButtonBuilder()
  .setCustomId('verification')
  .setStyle('PRIMARY')

// Fixed
const { ButtonStyle } = require('discord.js');
new ButtonBuilder()
  .setCustomId('verification')
  .setStyle(ButtonStyle.Primary)

// Wrong
new TextInputBuilder()
  .setCustomId('verification')
  .setStyle('SHORT')

// Fixed
const { TextInputStyle } = require('discord.js');
new TextInputBuilder()
  .setCustomId('verification')
  .setStyle(TextInputStyle.Short)

Errors with activity types: setPresence activity type in discord.js v14 can only be set to “PLAYING”

If message.content doesn’t have any value, add the GatewayIntentBits.MessageContent enum to your intents array

For more breaking changes, you can visit the discord.js guide: https://discordjs.guide/additional-info/changes-in-v14.html

Leave a Comment