我刚刚更新了我的不和.js从v13到v14,有很多错误.

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 100s:

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

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

推荐答案

不一致js v14包含许多突破性的更改.现在需要使用Node 16.9或更高版本,因此请确保使用upgrade to the latest LTS version.

此版本的v14使用Discord API v10.

意图错误:

// 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,
  ],
});

对于GatewayIntentBits的完整列表,您可以 Select read this answer.

Errors with interactions:

一些交互类型的防护装置已被拆除.您可以将interaction.typeInteractionType enum进行比较.

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) {}

通道错误:

一些通道型防护装置已拆除.要缩小通道,可以将channel.typeChannelType enum进行比较.

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) {}

对于ChannelType人的完整列表,您可以 Select read this answer人.

此外,还有一些新型防护装置:

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

生成器和嵌入错误:

MessageEmbed已重命名为EmbedBuilder.

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

MessageComponents已重命名;它们不再有Message前缀,现在有Builder后缀.

// 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();

枚举错误:

任何用于接受枚举参数的字符串或数字类型的区域现在只接受独占数字.

// 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)

活动类型错误:setPresence activity type in discord.js v14 can only be set to "PLAYING"

要获得更多突破性的更改,您可以访问discord.js指南:https://discordjs.guide/additional-info/changes-in-v14.html

Javascript相关问答推荐

如何将元素排列得彼此靠近?

将下拉分区与工具提示结合起来

使用ReactJS对Ant Design表中的空值进行排序

使用Apps Script缩短谷歌表中的URL?

在JavaScript中对大型级联数组进行切片的最有效方法?

RxJS setTimeout操作符等效

zoom svg以适应圆

Google图表时间轴—更改hAxis文本 colored颜色

从WooCommerce Checkout Country字段重新排序国家,保持国家同步

Rehype将hashtag呈现为URL

将字符串UTC Date转换为ngx—counting leftTime配置值的数字

更改JSON中使用AJAX返回的图像的路径

并不是所有的iframe都被更换

PDF工具包阿拉伯字体的反转数字

如何强制Sphinx中的自定义js/css文件始终加载更改而不缓存?

如何将zoom 变换应用到我的d3力有向图?

TinyMCE 6导致Data:Image对象通过提供的脚本过度上载

为什么云存储中的文件不能公开使用?

我想使用GAS和HTML将从Electron 表格中获得的信息插入到文本字段的初始值中

为什么延迟在我的laravel项目中不起作用?