我刚刚将我的discord.js从v13更新到v14,但出现了许多错误。
与message
和interaction
事件相关的错误:
无论是message
还是interaction
事件都没有触发。
与意图相关的错误:
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.
interaction
错误:
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
通道错误:
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
构建器和嵌入的错误:
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
枚举类型的错误:
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
new ActionRowBuilder()
是不够的。你需要new ActionRowBuilder<ComponentType>()
。例如:new ActionRowBuilder<ButtonBuilder>()
。这样你只能添加 ButtonBuilders 到组件中,并且它不会允许你将其发送到模态框中(因为按钮不允许在那里)。 - MrMythical