从 Discord.js v11 迁移到 v12:解决常见问题
升级到 Discord.js v12 时,您可能会遇到以下错误重大变化。以下是一些常见问题及其解决方案:
Managers
类似message.member.addRole的方法, Guild#createChannel 和 TextBasedChannel#fetchMessages 已移至各自的管理器。例如:
await message.member.roles.add(role); await message.guild.channels.create('welcome'); const messages = await message.channel.messages.fetch();
Collection
Collection 类现在只接受.find 和 .findKey 的函数。使用 lambda 表达式代替属性键和值。例如:
collection.find(item => item.property === 'value');
RichEmbed/MessageEmbed
addBlankField 方法已被删除。要添加空白字段,请使用:
embed.addField('\u200B', '\u200B');
Voice
所有 VoiceConnection/VoiceBroadcast#play*** 方法已统一在一个单人玩法。例如:
const dispatcher = connection.play('./music.mp3');
图像 URL
User#displayAvatarURL 和 Guild#iconURL 现在是方法。它们需要传递 ImageURLOptions 对象进行自定义:
const avatar = user.displayAvatarURL(); const icon = mesage.guild.iconURL();
其他信息
有关 v12 重大更改的综合指南,请参阅官方更新指南和变更日志。 Discord.js 文档可以帮助您找到特定的方法和属性。
免责声明: 提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发到邮箱:[email protected] 我们会第一时间内为您处理。
Copyright© 2022 湘ICP备2022001581号-3