Home > Web Front-end > JS Tutorial > What are the Key Breaking Changes in Discord.js v14?

What are the Key Breaking Changes in Discord.js v14?

Linda Hamilton
Release: 2024-12-05 12:43:11
Original
1013 people have browsed it

What are the Key Breaking Changes in Discord.js v14?

Discord.js v14 Breaking Changes: A Detailed Analysis

Breaking Changes Overview

Discord.js v14 introduces numerous breaking changes, primarily due to its transition to Discord API v10. These changes require Node 16.9 or higher and affect various aspects of the library, including message and interaction events, intents, interactions, channels, builders and embeds, enums, and activity types.

Message and Interaction Events

The message and interaction events have been removed. Instead, you can use messageCreate and interactionCreate events respectively.

Intents

Intents now require the GatewayIntentBits enum instead of FLAGS. To access GUILDS and GUILD_MESSAGES, for example, you would use:

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

Interactions

Interaction type guards have been removed. Instead, compare interaction.type against the InteractionType enum:

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

// v14
if (interaction.type === InteractionType.ApplicationCommand) {}
Copy after login

Channels

Channel type guards have been removed. Compare channel.type against the ChannelType enum:

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

// v14
if (channel.type === ChannelType.GuildText) {}
Copy after login

Builders and Embeds

MessageEmbed has been renamed to EmbedBuilder. MessageAttachment has been renamed to AttachmentBuilder and accepts an AttachmentData object instead of the second parameter. MessageComponents have been renamed to remove the Message prefix and add a Builder suffix:

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

// v14
const { AttachmentBuilder } = require('discord.js');
const attachment = new AttachmentBuilder(buffer, { name: 'image.png' });

// v14
const { ButtonBuilder } = require('discord.js');
const button = new ButtonBuilder();
Copy after login

Enums

Enums now only accept numbers. Any areas that previously accepted strings or numbers will now require numbers:

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

Activity Types

The activity type in setPresence can now only be set to "PLAYING."

Additional Information

For more comprehensive information on breaking changes, consult the Discord.js guide at https://discordjs.guide/additional-info/changes-in-v14.html.

The above is the detailed content of What are the Key Breaking Changes in Discord.js v14?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template