最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Discord.js v13 code breaks when upgrading to v14 - Stack Overflow

programmeradmin2浏览0评论

I've just updated my discord.js from v13 to v14 and there are many errors.

Errors with message and interaction events:

Neither message nor interaction events fire.

Errors with intents:

const client = new Client({
  intents: [
    Intents.FLAGS.GUILDS,
    Intents.FLAGS.GUILD_MESSAGES,
    Intents.FLAGS.GUILD_MESSAGE_REACTIONS,
  ],
});
//     Intents.FLAGS.GUILDS,
//            ^
//
// TypeError: Cannot read properties of undefined (reading 'FLAGS')

const client = new Client({
  intents: ['GUILDS', 'GUILD_MEMBERS', 'GUILD_MESSAGES'],
});
//    throw new RangeError(ErrorCodes.BitFieldInvalid, bit);
//
// RangeError [BitFieldInvalid]: Invalid bitfield flag or number: GUILDS.

Errors with interactions:

if (interaction.isCommand()) {}
// TypeError: interaction.isCommand is not a function

if (interaction.isAutocomplete()) {}
// TypeError: interaction.isAutocomplete is not a function

if (interaction.isMessageComponent()) {}
// TypeError: interaction.isMessageComponent is not a function

if (interaction.isModalSubmit()) {}
// TypeError: interaction.isModalSubmit is not a function

Errors with channels:

if (message.channel.isText()) {}
// TypeError: channel.isText is not a function

if (message.channel.isVoice()) {}
// TypeError: channel.isVoice is not a function

if (message.channel.isDM()) {}
// TypeError: channel.isDM is not a function

if (message.channel.isCategory()) {}
// TypeError: channel.isCategory is not a function

Errors with builders and embeds:

const embed = new MessageEmbed();
//  const embed = new MessageEmbed();
//                ^
//
// TypeError: MessageEmbed is not a constructor

const button = new MessageButton();
//  const button = new MessageButton();
//                 ^
//
// TypeError: MessageButton is not a constructor

const actionRow = new MessageActionRow();
//  const actionRow = new MessageActionRow();
//                    ^
//
// TypeError: MessageActionRow is not a constructor

const selectMenu = new MessageSelectMenu();
//  const selectMenu = new MessageSelectMenu();
//                     ^
//
// TypeError: MessageSelectMenu is not a constructor

const textInput = new TextInputComponent();
//  const textInput = new TextInputComponent();
//                    ^
//
// TypeError: TextInputComponent is not a constructor

const modal = new Modal();
//  const modal = new Modal();
//                ^
//
// TypeError: Modal is not a constructor

const attachment = new MessageAttachment();
//  const attachment = new MessageAttachment();
//                     ^
//
// TypeError: MessageAttachment is not a constructor

Errors with enums:

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

// UnknownEnumValueError: Expected the value to be one of the following enum values:
//     at NativeEnumValidator.handle

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

// UnknownEnumValueError: Expected the value to be one of the following enum values:
//     at NativeEnumValidator.handle

I've just updated my discord.js from v13 to v14 and there are many errors.

Errors with message and interaction events:

Neither message nor interaction events fire.

Errors with intents:

const client = new Client({
  intents: [
    Intents.FLAGS.GUILDS,
    Intents.FLAGS.GUILD_MESSAGES,
    Intents.FLAGS.GUILD_MESSAGE_REACTIONS,
  ],
});
//     Intents.FLAGS.GUILDS,
//            ^
//
// TypeError: Cannot read properties of undefined (reading 'FLAGS')

const client = new Client({
  intents: ['GUILDS', 'GUILD_MEMBERS', 'GUILD_MESSAGES'],
});
//    throw new RangeError(ErrorCodes.BitFieldInvalid, bit);
//
// RangeError [BitFieldInvalid]: Invalid bitfield flag or number: GUILDS.

Errors with interactions:

if (interaction.isCommand()) {}
// TypeError: interaction.isCommand is not a function

if (interaction.isAutocomplete()) {}
// TypeError: interaction.isAutocomplete is not a function

if (interaction.isMessageComponent()) {}
// TypeError: interaction.isMessageComponent is not a function

if (interaction.isModalSubmit()) {}
// TypeError: interaction.isModalSubmit is not a function

Errors with channels:

if (message.channel.isText()) {}
// TypeError: channel.isText is not a function

if (message.channel.isVoice()) {}
// TypeError: channel.isVoice is not a function

if (message.channel.isDM()) {}
// TypeError: channel.isDM is not a function

if (message.channel.isCategory()) {}
// TypeError: channel.isCategory is not a function

Errors with builders and embeds:

const embed = new MessageEmbed();
//  const embed = new MessageEmbed();
//                ^
//
// TypeError: MessageEmbed is not a constructor

const button = new MessageButton();
//  const button = new MessageButton();
//                 ^
//
// TypeError: MessageButton is not a constructor

const actionRow = new MessageActionRow();
//  const actionRow = new MessageActionRow();
//                    ^
//
// TypeError: MessageActionRow is not a constructor

const selectMenu = new MessageSelectMenu();
//  const selectMenu = new MessageSelectMenu();
//                     ^
//
// TypeError: MessageSelectMenu is not a constructor

const textInput = new TextInputComponent();
//  const textInput = new TextInputComponent();
//                    ^
//
// TypeError: TextInputComponent is not a constructor

const modal = new Modal();
//  const modal = new Modal();
//                ^
//
// TypeError: Modal is not a constructor

const attachment = new MessageAttachment();
//  const attachment = new MessageAttachment();
//                     ^
//
// TypeError: MessageAttachment is not a constructor

Errors with enums:

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

// UnknownEnumValueError: Expected the value to be one of the following enum values:
//     at NativeEnumValidator.handle

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

// UnknownEnumValueError: Expected the value to be one of the following enum values:
//     at NativeEnumValidator.handle
Share Improve this question edited Apr 7, 2023 at 16:04 Zsolt Meszaros asked Jul 18, 2022 at 21:30 Zsolt MeszarosZsolt Meszaros 23.2k19 gold badges57 silver badges68 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 16

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 message and interaction events:

The message and interaction events are now removed. You can use the messageCreate and interactionCreate events instead.

// v13
client.on('message', (message) => {
  console.log(`
发布评论

评论列表(0)

  1. 暂无评论